Skip to content

Commit 8c39f76

Browse files
committed
Feedback
1 parent 7b6b7c9 commit 8c39f76

File tree

1 file changed

+23
-23
lines changed
  • packages/database/src/core/util/libs

1 file changed

+23
-23
lines changed

packages/database/src/core/util/libs/parser.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { Path } from '../Path';
1818
import { RepoInfo } from '../../RepoInfo';
19-
import { warnIfPageIsSecure, fatal } from '../util';
19+
import { warnIfPageIsSecure, warn, fatal } from '../util';
2020

2121
/**
2222
* @param {!string} pathString
@@ -39,18 +39,19 @@ function decodePath(pathString: string): string {
3939

4040
/**
4141
* @param {!string} queryString
42-
* @return {!Map<string, string>} key value hash
42+
* @return {!{[key:string]:string}} key value hash
4343
*/
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);
5455
}
5556
}
5657
return results;
@@ -143,17 +144,17 @@ export const parseURL = function(
143144
if (slashInd === -1) {
144145
slashInd = dataURL.length;
145146
}
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;
149150
}
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));
154155
}
155156
let queryParams = decodeQuery(
156-
dataURL.substring(Math.min(dataURL.length, questionInd + 1))
157+
dataURL.substring(Math.min(dataURL.length, questionMarkInd))
157158
);
158159

159160
// If we have a port, use scheme for determining if it's secure.
@@ -176,9 +177,8 @@ export const parseURL = function(
176177
domain = 'localhost';
177178
}
178179
// 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'];
182182
}
183183
}
184184

0 commit comments

Comments
 (0)