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) {
2798
2798
const entries = search . split ( '&' ) . map ( ( i ) => i . split ( '=' ) ) ;
2799
2799
const data = { } ;
2800
2800
entries . forEach ( ( [ key , value ] ) => {
2801
- value = decodeURIComponent ( value . replace ( / \+ / g, '%20' ) ) ;
2801
+ value = decodeURIComponent ( String ( value || '' ) . replace ( / \+ / g, '%20' ) ) ;
2802
2802
if ( ! key . includes ( '[' ) ) {
2803
2803
data [ key ] = value ;
2804
2804
}
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ function fromQueryString(search: string) {
104
104
const data : any = { } ;
105
105
106
106
entries . forEach ( ( [ key , value ] ) => {
107
- value = decodeURIComponent ( value . replace ( / \+ / g, '%20' ) ) ;
107
+ value = decodeURIComponent ( String ( value || '' ) . replace ( / \+ / g, '%20' ) ) ;
108
108
109
109
if ( ! key . includes ( '[' ) ) {
110
110
data [ key ] = value ;
Original file line number Diff line number Diff line change @@ -115,6 +115,32 @@ describe('url_utils', () => {
115
115
expect ( urlUtils . search ) . toEqual ( '' ) ;
116
116
} ) ;
117
117
} ) ;
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
+ } ) ;
118
144
} ) ;
119
145
120
146
describe ( 'HistoryStrategy' , ( ) => {
You can’t perform that action at this time.
0 commit comments