Skip to content

Commit a89d83c

Browse files
committed
Fix other incorrect usages of split
1 parent 83ff31b commit a89d83c

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/browser/client.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { URI } from "vs/base/common/uri";
33
import { registerSingleton } from "vs/platform/instantiation/common/extensions";
44
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
55
import { ILocalizationsService } from "vs/platform/localizations/common/localizations";
6-
import { LocalizationsService } from "vs/workbench/services/localizations/electron-browser/localizationsService";
6+
import { PersistentConnectionEventType } from "vs/platform/remote/common/remoteAgentConnection";
77
import { ITelemetryService } from "vs/platform/telemetry/common/telemetry";
88
import { coderApi, vscodeApi } from "vs/server/src/browser/api";
99
import { IUploadService, UploadService } from "vs/server/src/browser/upload";
1010
import { INodeProxyService, NodeProxyChannelClient } from "vs/server/src/common/nodeProxy";
1111
import { TelemetryChannelClient } from "vs/server/src/common/telemetry";
12+
import { split } from "vs/server/src/common/util";
1213
import "vs/workbench/contrib/localizations/browser/localizations.contribution";
14+
import { LocalizationsService } from "vs/workbench/services/localizations/electron-browser/localizationsService";
1315
import { IRemoteAgentService } from "vs/workbench/services/remote/common/remoteAgentService";
14-
import { PersistentConnectionEventType } from "vs/platform/remote/common/remoteAgentConnection";
1516

1617
class TelemetryService extends TelemetryChannelClient {
1718
public constructor(
@@ -79,7 +80,7 @@ export const withQuery = (url: string, replace: Query): string => {
7980
const uri = URI.parse(url);
8081
const query = { ...replace };
8182
uri.query.split("&").forEach((kv) => {
82-
const [key, value] = kv.split("=", 2);
83+
const [key, value] = split(kv, "=");
8384
if (!(key in query)) {
8485
query[key] = value;
8586
}

src/common/util.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Split a string up to the delimiter. If the delimiter doesn't exist the first
3+
* item will have all the text and the second item will be an empty string.
4+
*/
5+
export const split = (str: string, delimiter: string): [string, string] => {
6+
const index = str.indexOf(delimiter);
7+
return index !== -1
8+
? [str.substring(0, index).trim(), str.substring(index + 1)]
9+
: [str, ""];
10+
};

src/node/server.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { resolveCommonProperties } from "vs/platform/telemetry/node/commonProper
5656
import { UpdateChannel } from "vs/platform/update/electron-main/updateIpc";
5757
import { INodeProxyService, NodeProxyChannel } from "vs/server/src/common/nodeProxy";
5858
import { TelemetryChannel } from "vs/server/src/common/telemetry";
59+
import { split } from "vs/server/src/common/util";
5960
import { ExtensionEnvironmentChannel, FileProviderChannel, NodeProxyService } from "vs/server/src/node/channel";
6061
import { Connection, ExtensionHostConnection, ManagementConnection } from "vs/server/src/node/connection";
6162
import { TelemetryClient } from "vs/server/src/node/insights";
@@ -212,8 +213,8 @@ export abstract class Server {
212213
}
213214

214215
protected withBase(request: http.IncomingMessage, path: string): string {
215-
const split = request.url ? request.url.split("?", 2) : [];
216-
return `${this.protocol}://${request.headers.host}${this.options.basePath}${path}${split.length === 2 ? `?${split[1]}` : ""}`;
216+
const [, query] = request.url ? split(request.url, "?") : [];
217+
return `${this.protocol}://${request.headers.host}${this.options.basePath}${path}${query ? `?${query}` : ""}`;
217218
}
218219

219220
private isAllowedRequestPath(path: string): boolean {
@@ -440,11 +441,8 @@ export abstract class Server {
440441
const cookies: { [key: string]: string } = {};
441442
if (request.headers.cookie) {
442443
request.headers.cookie.split(";").forEach((keyValue) => {
443-
// key=value -> { [key]: value } and key -> { [key]: "" }
444-
const index = keyValue.indexOf("=");
445-
const key = keyValue.substring(0, index).trim();
446-
const value = keyValue.substring(index + 1);
447-
cookies[key || value] = decodeURI(key ? value : "");
444+
const [key, value] = split(keyValue, "=");
445+
cookies[key] = decodeURI(value);
448446
});
449447
}
450448
return cookies as T;

0 commit comments

Comments
 (0)