File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -2798,7 +2798,7 @@ function fromQueryString(search) {
27982798 const entries = search . split ( '&' ) . map ( ( i ) => i . split ( '=' ) ) ;
27992799 const data = { } ;
28002800 entries . forEach ( ( [ key , value ] ) => {
2801- value = decodeURIComponent ( value . replace ( / \+ / g, '%20' ) ) ;
2801+ value = decodeURIComponent ( String ( value || '' ) . replace ( / \+ / g, '%20' ) ) ;
28022802 if ( ! key . includes ( '[' ) ) {
28032803 data [ key ] = value ;
28042804 }
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ function fromQueryString(search: string) {
104104 const data : any = { } ;
105105
106106 entries . forEach ( ( [ key , value ] ) => {
107- value = decodeURIComponent ( value . replace ( / \+ / g, '%20' ) ) ;
107+ value = decodeURIComponent ( String ( value || '' ) . replace ( / \+ / g, '%20' ) ) ;
108108
109109 if ( ! key . includes ( '[' ) ) {
110110 data [ key ] = value ;
Original file line number Diff line number Diff line change @@ -115,6 +115,32 @@ describe('url_utils', () => {
115115 expect ( urlUtils . search ) . toEqual ( '' ) ;
116116 } ) ;
117117 } ) ;
118+
119+ describe ( 'fromQueryString' , ( ) => {
120+ const urlUtils : UrlUtils = new UrlUtils ( window . location . href ) ;
121+
122+ beforeEach ( ( ) => {
123+ // Reset search before each test
124+ urlUtils . search = '' ;
125+ } ) ;
126+
127+ it ( 'parses a query string with value' , ( ) => {
128+ urlUtils . search = '?param1=value1' ;
129+ expect ( urlUtils . get ( 'param1' ) ) . toEqual ( 'value1' ) ;
130+ } ) ;
131+
132+ it ( 'parses a query string with empty value' , ( ) => {
133+ urlUtils . search = '?param1=¶m2=value2' ;
134+ expect ( urlUtils . get ( 'param1' ) ) . toEqual ( '' ) ;
135+ expect ( urlUtils . get ( 'param2' ) ) . toEqual ( 'value2' ) ;
136+ } ) ;
137+
138+ it ( 'parses a query string without equal sign' , ( ) => {
139+ urlUtils . search = '?param1¶m2=value2' ;
140+ expect ( urlUtils . get ( 'param1' ) ) . toEqual ( '' ) ;
141+ expect ( urlUtils . get ( 'param2' ) ) . toEqual ( 'value2' ) ;
142+ } ) ;
143+ } ) ;
118144 } ) ;
119145
120146 describe ( 'HistoryStrategy' , ( ) => {
You can’t perform that action at this time.
0 commit comments