File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -185,8 +185,8 @@ function urlencode(o) {
185185// intentionally using regex and not <a/> href parsing trick because React Native and other
186186// environments where DOM might not be available
187187function parseUrl ( url ) {
188+ if ( typeof url !== 'string' ) return { } ;
188189 var match = url . match ( / ^ ( ( [ ^ : \/ ? # ] + ) : ) ? ( \/ \/ ( [ ^ \/ ? # ] * ) ) ? ( [ ^ ? # ] * ) ( \? ( [ ^ # ] * ) ) ? ( # ( .* ) ) ? $ / ) ;
189- if ( ! match ) return { } ;
190190
191191 // coerce to undefined values to empty string so we don't get 'undefined'
192192 var query = match [ 6 ] || '' ;
Original file line number Diff line number Diff line change @@ -353,6 +353,15 @@ describe('utils', function() {
353353 // from example.com => example.com/example.com/foo (valid url).
354354 } ) ;
355355 } ) ;
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+ } ) ;
356365 } ) ;
357366
358367 describe ( 'wrappedCallback' , function ( ) {
You can’t perform that action at this time.
0 commit comments