File tree 2 files changed +10
-1
lines changed
2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -185,8 +185,8 @@ function urlencode(o) {
185
185
// intentionally using regex and not <a/> href parsing trick because React Native and other
186
186
// environments where DOM might not be available
187
187
function parseUrl ( url ) {
188
+ if ( typeof url !== 'string' ) return { } ;
188
189
var match = url . match ( / ^ ( ( [ ^ : \/ ? # ] + ) : ) ? ( \/ \/ ( [ ^ \/ ? # ] * ) ) ? ( [ ^ ? # ] * ) ( \? ( [ ^ # ] * ) ) ? ( # ( .* ) ) ? $ / ) ;
189
- if ( ! match ) return { } ;
190
190
191
191
// coerce to undefined values to empty string so we don't get 'undefined'
192
192
var query = match [ 6 ] || '' ;
Original file line number Diff line number Diff line change @@ -353,6 +353,15 @@ describe('utils', function() {
353
353
// from example.com => example.com/example.com/foo (valid url).
354
354
} ) ;
355
355
} ) ;
356
+
357
+ it ( 'should return an empty object for invalid input' , function ( ) {
358
+ assert . deepEqual ( parseUrl ( ) , { } ) ;
359
+ assert . deepEqual ( parseUrl ( 42 ) , { } ) ;
360
+ assert . deepEqual ( parseUrl ( [ ] ) , { } ) ;
361
+ assert . deepEqual ( parseUrl ( { } ) , { } ) ;
362
+ assert . deepEqual ( parseUrl ( null ) , { } ) ;
363
+ assert . deepEqual ( parseUrl ( undefined ) , { } ) ;
364
+ } ) ;
356
365
} ) ;
357
366
358
367
describe ( 'wrappedCallback' , function ( ) {
You can’t perform that action at this time.
0 commit comments