mirror of https://git.tuxpa.in/a/code-server.git
Fix other incorrect usages of `split`
This commit is contained in:
parent
83ff31b620
commit
a89d83cbba
|
@ -3,15 +3,16 @@ import { URI } from "vs/base/common/uri";
|
||||||
import { registerSingleton } from "vs/platform/instantiation/common/extensions";
|
import { registerSingleton } from "vs/platform/instantiation/common/extensions";
|
||||||
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
|
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
|
||||||
import { ILocalizationsService } from "vs/platform/localizations/common/localizations";
|
import { ILocalizationsService } from "vs/platform/localizations/common/localizations";
|
||||||
import { LocalizationsService } from "vs/workbench/services/localizations/electron-browser/localizationsService";
|
import { PersistentConnectionEventType } from "vs/platform/remote/common/remoteAgentConnection";
|
||||||
import { ITelemetryService } from "vs/platform/telemetry/common/telemetry";
|
import { ITelemetryService } from "vs/platform/telemetry/common/telemetry";
|
||||||
import { coderApi, vscodeApi } from "vs/server/src/browser/api";
|
import { coderApi, vscodeApi } from "vs/server/src/browser/api";
|
||||||
import { IUploadService, UploadService } from "vs/server/src/browser/upload";
|
import { IUploadService, UploadService } from "vs/server/src/browser/upload";
|
||||||
import { INodeProxyService, NodeProxyChannelClient } from "vs/server/src/common/nodeProxy";
|
import { INodeProxyService, NodeProxyChannelClient } from "vs/server/src/common/nodeProxy";
|
||||||
import { TelemetryChannelClient } from "vs/server/src/common/telemetry";
|
import { TelemetryChannelClient } from "vs/server/src/common/telemetry";
|
||||||
|
import { split } from "vs/server/src/common/util";
|
||||||
import "vs/workbench/contrib/localizations/browser/localizations.contribution";
|
import "vs/workbench/contrib/localizations/browser/localizations.contribution";
|
||||||
|
import { LocalizationsService } from "vs/workbench/services/localizations/electron-browser/localizationsService";
|
||||||
import { IRemoteAgentService } from "vs/workbench/services/remote/common/remoteAgentService";
|
import { IRemoteAgentService } from "vs/workbench/services/remote/common/remoteAgentService";
|
||||||
import { PersistentConnectionEventType } from "vs/platform/remote/common/remoteAgentConnection";
|
|
||||||
|
|
||||||
class TelemetryService extends TelemetryChannelClient {
|
class TelemetryService extends TelemetryChannelClient {
|
||||||
public constructor(
|
public constructor(
|
||||||
|
@ -79,7 +80,7 @@ export const withQuery = (url: string, replace: Query): string => {
|
||||||
const uri = URI.parse(url);
|
const uri = URI.parse(url);
|
||||||
const query = { ...replace };
|
const query = { ...replace };
|
||||||
uri.query.split("&").forEach((kv) => {
|
uri.query.split("&").forEach((kv) => {
|
||||||
const [key, value] = kv.split("=", 2);
|
const [key, value] = split(kv, "=");
|
||||||
if (!(key in query)) {
|
if (!(key in query)) {
|
||||||
query[key] = value;
|
query[key] = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Split a string up to the delimiter. If the delimiter doesn't exist the first
|
||||||
|
* item will have all the text and the second item will be an empty string.
|
||||||
|
*/
|
||||||
|
export const split = (str: string, delimiter: string): [string, string] => {
|
||||||
|
const index = str.indexOf(delimiter);
|
||||||
|
return index !== -1
|
||||||
|
? [str.substring(0, index).trim(), str.substring(index + 1)]
|
||||||
|
: [str, ""];
|
||||||
|
};
|
|
@ -56,6 +56,7 @@ import { resolveCommonProperties } from "vs/platform/telemetry/node/commonProper
|
||||||
import { UpdateChannel } from "vs/platform/update/electron-main/updateIpc";
|
import { UpdateChannel } from "vs/platform/update/electron-main/updateIpc";
|
||||||
import { INodeProxyService, NodeProxyChannel } from "vs/server/src/common/nodeProxy";
|
import { INodeProxyService, NodeProxyChannel } from "vs/server/src/common/nodeProxy";
|
||||||
import { TelemetryChannel } from "vs/server/src/common/telemetry";
|
import { TelemetryChannel } from "vs/server/src/common/telemetry";
|
||||||
|
import { split } from "vs/server/src/common/util";
|
||||||
import { ExtensionEnvironmentChannel, FileProviderChannel, NodeProxyService } from "vs/server/src/node/channel";
|
import { ExtensionEnvironmentChannel, FileProviderChannel, NodeProxyService } from "vs/server/src/node/channel";
|
||||||
import { Connection, ExtensionHostConnection, ManagementConnection } from "vs/server/src/node/connection";
|
import { Connection, ExtensionHostConnection, ManagementConnection } from "vs/server/src/node/connection";
|
||||||
import { TelemetryClient } from "vs/server/src/node/insights";
|
import { TelemetryClient } from "vs/server/src/node/insights";
|
||||||
|
@ -212,8 +213,8 @@ export abstract class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected withBase(request: http.IncomingMessage, path: string): string {
|
protected withBase(request: http.IncomingMessage, path: string): string {
|
||||||
const split = request.url ? request.url.split("?", 2) : [];
|
const [, query] = request.url ? split(request.url, "?") : [];
|
||||||
return `${this.protocol}://${request.headers.host}${this.options.basePath}${path}${split.length === 2 ? `?${split[1]}` : ""}`;
|
return `${this.protocol}://${request.headers.host}${this.options.basePath}${path}${query ? `?${query}` : ""}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private isAllowedRequestPath(path: string): boolean {
|
private isAllowedRequestPath(path: string): boolean {
|
||||||
|
@ -440,11 +441,8 @@ export abstract class Server {
|
||||||
const cookies: { [key: string]: string } = {};
|
const cookies: { [key: string]: string } = {};
|
||||||
if (request.headers.cookie) {
|
if (request.headers.cookie) {
|
||||||
request.headers.cookie.split(";").forEach((keyValue) => {
|
request.headers.cookie.split(";").forEach((keyValue) => {
|
||||||
// key=value -> { [key]: value } and key -> { [key]: "" }
|
const [key, value] = split(keyValue, "=");
|
||||||
const index = keyValue.indexOf("=");
|
cookies[key] = decodeURI(value);
|
||||||
const key = keyValue.substring(0, index).trim();
|
|
||||||
const value = keyValue.substring(index + 1);
|
|
||||||
cookies[key || value] = decodeURI(key ? value : "");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return cookies as T;
|
return cookies as T;
|
||||||
|
|
Loading…
Reference in New Issue