@@ -136,6 +136,27 @@ const isPlainObject = (val) => {
136136 return ( prototype === null || prototype === Object . prototype || Object . getPrototypeOf ( prototype ) === null ) && ! ( toStringTag in val ) && ! ( iterator in val ) ;
137137}
138138
139+ /**
140+ * Determine if a value is an empty object (safely handles Buffers)
141+ *
142+ * @param {* } val The value to test
143+ *
144+ * @returns {boolean } True if value is an empty object, otherwise false
145+ */
146+ const isEmptyObject = ( val ) => {
147+ // Early return for non-objects or Buffers to prevent RangeError
148+ if ( ! isObject ( val ) || isBuffer ( val ) ) {
149+ return false ;
150+ }
151+
152+ try {
153+ return Object . keys ( val ) . length === 0 && Object . getPrototypeOf ( val ) === Object . prototype ;
154+ } catch ( e ) {
155+ // Fallback for any other objects that might cause RangeError with Object.keys()
156+ return false ;
157+ }
158+ }
159+
139160/**
140161 * Determine if a value is a Date
141162 *
@@ -258,6 +279,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
258279 fn . call ( null , obj [ i ] , i , obj ) ;
259280 }
260281 } else {
282+ // Buffer check
283+ if ( isBuffer ( obj ) ) {
284+ return ;
285+ }
286+
261287 // Iterate over object keys
262288 const keys = allOwnKeys ? Object . getOwnPropertyNames ( obj ) : Object . keys ( obj ) ;
263289 const len = keys . length ;
@@ -271,6 +297,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
271297}
272298
273299function findKey ( obj , key ) {
300+ if ( isBuffer ( obj ) ) {
301+ return null ;
302+ }
303+
274304 key = key . toLowerCase ( ) ;
275305 const keys = Object . keys ( obj ) ;
276306 let i = keys . length ;
@@ -624,6 +654,11 @@ const toJSONObject = (obj) => {
624654 return ;
625655 }
626656
657+ //Buffer check
658+ if ( isBuffer ( source ) ) {
659+ return source ;
660+ }
661+
627662 if ( ! ( 'toJSON' in source ) ) {
628663 stack [ i ] = source ;
629664 const target = isArray ( source ) ? [ ] : { } ;
@@ -695,6 +730,7 @@ export default {
695730 isBoolean,
696731 isObject,
697732 isPlainObject,
733+ isEmptyObject,
698734 isReadableStream,
699735 isRequest,
700736 isResponse,
0 commit comments