File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Expand file tree Collapse file tree 3 files changed +29
-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,33 @@ 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=¶m2=value2' ;
129
+ expect ( urlUtils . get ( 'param1' ) ) . toEqual ( '' ) ;
130
+ expect ( urlUtils . get ( 'param2' ) ) . toEqual ( 'value2' ) ;
131
+ } ) ;
132
+
133
+ it ( 'parses a query string with empty value' , ( ) => {
134
+ urlUtils . search = '?param1=¶m2=value2' ;
135
+ expect ( urlUtils . get ( 'param1' ) ) . toEqual ( '' ) ;
136
+ expect ( urlUtils . get ( 'param2' ) ) . toEqual ( 'value2' ) ;
137
+ } ) ;
138
+
139
+ it ( 'parses a query string without equal sign' , ( ) => {
140
+ urlUtils . search = '?param1¶m2=value2' ;
141
+ expect ( urlUtils . get ( 'param1' ) ) . toEqual ( '' ) ;
142
+ expect ( urlUtils . get ( 'param2' ) ) . toEqual ( 'value2' ) ;
143
+ } ) ;
144
+ } ) ;
118
145
} ) ;
119
146
120
147
describe ( 'HistoryStrategy' , ( ) => {
You can’t perform that action at this time.
0 commit comments