@@ -37,6 +37,25 @@ function decodePath(pathString: string): string {
37
37
return pathStringDecoded ;
38
38
}
39
39
40
+ /**
41
+ * @param {!string } queryString
42
+ * @return {!Map<string, string> } key value hash
43
+ */
44
+ function decodeQuery ( queryString : string ) : Map < string , string > {
45
+ let results = new Map < string , string > ( ) ;
46
+ const pieces = queryString . split ( '&' ) ;
47
+ for ( let i = 0 ; i < pieces . length ; i ++ ) {
48
+ if ( pieces [ i ] . length > 0 ) {
49
+ try {
50
+ const piece = decodeURIComponent ( pieces [ i ] ) ;
51
+ const kv = piece . split ( '=' ) ;
52
+ results . set ( kv [ 0 ] , kv [ 1 ] ) ;
53
+ } catch ( e ) { }
54
+ }
55
+ }
56
+ return results ;
57
+ }
58
+
40
59
/**
41
60
*
42
61
* @param {!string } dataURL
@@ -119,13 +138,21 @@ export const parseURL = function(
119
138
dataURL = dataURL . substring ( colonInd + 2 ) ;
120
139
}
121
140
122
- // Parse host and path .
141
+ // Parse host, path, and query string .
123
142
let slashInd = dataURL . indexOf ( '/' ) ;
124
143
if ( slashInd === - 1 ) {
125
144
slashInd = dataURL . length ;
126
145
}
127
- host = dataURL . substring ( 0 , slashInd ) ;
128
- pathString = decodePath ( dataURL . substring ( slashInd ) ) ;
146
+ let questionInd = dataURL . indexOf ( '?' ) ;
147
+ if ( questionInd === - 1 ) {
148
+ questionInd = dataURL . length ;
149
+ }
150
+ host = dataURL . substring ( 0 , Math . min ( slashInd , questionInd ) ) ;
151
+ if ( slashInd < questionInd ) {
152
+ // For pathString, questionInd will always come after slashInd
153
+ pathString = decodePath ( dataURL . substring ( slashInd , questionInd ) ) ;
154
+ }
155
+ let queryParams = decodeQuery ( dataURL . substring ( Math . min ( dataURL . length , questionInd + 1 ) ) ) ;
129
156
130
157
// If we have a port, use scheme for determining if it's secure.
131
158
colonInd = host . indexOf ( ':' ) ;
@@ -147,17 +174,9 @@ export const parseURL = function(
147
174
domain = 'localhost' ;
148
175
}
149
176
// Support `ns` query param if subdomain not already set
150
- const queryStartIndex = host . indexOf ( '?' ) ;
151
- if ( queryStartIndex > 0 ) {
152
- if ( subdomain === '' ) {
153
- const queryString = host . substring ( queryStartIndex , host . length ) ;
154
- const match = queryString . match ( / n s = ( [ a - z A - Z 0 - 9 - ] + ) / ) ;
155
- if ( match . length > 0 ) {
156
- subdomain = match [ 1 ] ;
157
- }
158
- }
159
- // Always remove all query params from the host
160
- host = host . substring ( 0 , queryStartIndex ) ;
177
+ if ( subdomain === '' && queryParams . has ( 'ns' ) ) {
178
+ subdomain = queryParams . get ( 'ns' ) ;
179
+ console . log ( "here" , queryParams , subdomain ) ;
161
180
}
162
181
}
163
182
0 commit comments