16
16
17
17
import { Path } from '../Path' ;
18
18
import { RepoInfo } from '../../RepoInfo' ;
19
- import { warnIfPageIsSecure , fatal } from '../util' ;
19
+ import { warnIfPageIsSecure , warn , fatal } from '../util' ;
20
20
21
21
/**
22
22
* @param {!string } pathString
@@ -39,18 +39,19 @@ function decodePath(pathString: string): string {
39
39
40
40
/**
41
41
* @param {!string } queryString
42
- * @return {!Map< string, string> } key value hash
42
+ * @return {!{[key: string]: string} } key value hash
43
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 ) { }
44
+ function decodeQuery ( queryString : string ) : { [ key : string ] : string } {
45
+ let results = { } ;
46
+ if ( queryString . startsWith ( '?' ) ) {
47
+ queryString = queryString . substring ( 1 ) ;
48
+ }
49
+ for ( const segment of queryString . split ( '&' ) ) {
50
+ const kv = segment . split ( '=' ) ;
51
+ if ( kv . length === 2 ) {
52
+ results [ decodeURIComponent ( kv [ 0 ] ) ] = decodeURIComponent ( kv [ 1 ] ) ;
53
+ } else {
54
+ warn ( 'Invalid query string segment: ' + segment ) ;
54
55
}
55
56
}
56
57
return results ;
@@ -143,17 +144,17 @@ export const parseURL = function(
143
144
if ( slashInd === - 1 ) {
144
145
slashInd = dataURL . length ;
145
146
}
146
- let questionInd = dataURL . indexOf ( '?' ) ;
147
- if ( questionInd === - 1 ) {
148
- questionInd = dataURL . length ;
147
+ let questionMarkInd = dataURL . indexOf ( '?' ) ;
148
+ if ( questionMarkInd === - 1 ) {
149
+ questionMarkInd = dataURL . length ;
149
150
}
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 ) ) ;
151
+ host = dataURL . substring ( 0 , Math . min ( slashInd , questionMarkInd ) ) ;
152
+ if ( slashInd < questionMarkInd ) {
153
+ // For pathString, questionMarkInd will always come after slashInd
154
+ pathString = decodePath ( dataURL . substring ( slashInd , questionMarkInd ) ) ;
154
155
}
155
156
let queryParams = decodeQuery (
156
- dataURL . substring ( Math . min ( dataURL . length , questionInd + 1 ) )
157
+ dataURL . substring ( Math . min ( dataURL . length , questionMarkInd ) )
157
158
) ;
158
159
159
160
// If we have a port, use scheme for determining if it's secure.
@@ -176,9 +177,8 @@ export const parseURL = function(
176
177
domain = 'localhost' ;
177
178
}
178
179
// Support `ns` query param if subdomain not already set
179
- if ( subdomain === '' && queryParams . has ( 'ns' ) ) {
180
- subdomain = queryParams . get ( 'ns' ) ;
181
- console . log ( 'here' , queryParams , subdomain ) ;
180
+ if ( subdomain === '' && 'ns' in queryParams ) {
181
+ subdomain = queryParams [ 'ns' ] ;
182
182
}
183
183
}
184
184
0 commit comments