From 65cb3397673b922c1b6759d145a3a183feb3ee5d Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 1 Apr 2016 09:42:49 +0200 Subject: [PATCH] flip boolean, expose `skipEncoding` in API --- src/vs/base/common/uri.ts | 22 ++++++++++--------- src/vs/base/test/common/uri.test.ts | 16 +++++++------- src/vs/vscode.d.ts | 15 ++++++++----- .../services/editor/browser/editorService.ts | 2 +- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/vs/base/common/uri.ts b/src/vs/base/common/uri.ts index 1c33eb43b34..91db82f086d 100644 --- a/src/vs/base/common/uri.ts +++ b/src/vs/base/common/uri.ts @@ -255,21 +255,23 @@ export default class URI { /** * - * @param encode Encode the result, default is `true`. + * @param skipEncoding Do not encode the result, default is `false` */ - public toString(encode: boolean = true): string { - if (!encode) { - return URI._asFormatted(this, false); - } - if (!this._formatted) { - this._formatted = URI._asFormatted(this, true); + public toString(skipEncoding: boolean = false): string { + if (!skipEncoding) { + if (!this._formatted) { + this._formatted = URI._asFormatted(this, false); + } + return this._formatted; + } else { + // we don't cache that + return URI._asFormatted(this, true); } - return this._formatted; } - private static _asFormatted(uri: URI, encode: boolean): string { + private static _asFormatted(uri: URI, skipEncoding: boolean): string { - const encoder = encode + const encoder = !skipEncoding ? encodeURIComponent2 : encodeNoop; diff --git a/src/vs/base/test/common/uri.test.ts b/src/vs/base/test/common/uri.test.ts index fe958f93083..90b8e027059 100644 --- a/src/vs/base/test/common/uri.test.ts +++ b/src/vs/base/test/common/uri.test.ts @@ -43,19 +43,19 @@ suite('URI', () => { }); test('http#toString, encode=FALSE', () => { - assert.equal(URI.create('http', 'a-test-site.com', '/', 'test=true').toString(false), 'http://a-test-site.com/?test=true'); - assert.equal(URI.create('http', 'a-test-site.com', '/', '', 'test=true').toString(false), 'http://a-test-site.com/#test=true'); - assert.equal(URI.create().withScheme('http').withPath('/api/files/test.me').withQuery('t=1234').toString(false), 'http:/api/files/test.me?t=1234'); + assert.equal(URI.create('http', 'a-test-site.com', '/', 'test=true').toString(true), 'http://a-test-site.com/?test=true'); + assert.equal(URI.create('http', 'a-test-site.com', '/', '', 'test=true').toString(true), 'http://a-test-site.com/#test=true'); + assert.equal(URI.create().withScheme('http').withPath('/api/files/test.me').withQuery('t=1234').toString(true), 'http:/api/files/test.me?t=1234'); var value = URI.parse('file://shares/pröjects/c%23/#l12'); assert.equal(value.authority, 'shares'); assert.equal(value.path, '/pröjects/c#/'); assert.equal(value.fragment, 'l12'); assert.equal(value.toString(), 'file://shares/pr%C3%B6jects/c%23/#l12'); - assert.equal(value.toString(false), 'file://shares/pröjects/c%23/#l12'); + assert.equal(value.toString(true), 'file://shares/pröjects/c%23/#l12'); - var uri2 = URI.parse(value.toString(false)); - var uri3 = URI.parse(value.toString(true)); + var uri2 = URI.parse(value.toString(true)); + var uri3 = URI.parse(value.toString()); assert.equal(uri2.authority, uri3.authority); assert.equal(uri2.path, uri3.path); assert.equal(uri2.query, uri3.query); @@ -353,7 +353,7 @@ suite('URI', () => { let uri = URI.parse('http://go.microsoft.com/fwlink/?LinkId=518008'); assert.equal(uri.query, 'LinkId=518008'); - assert.equal(uri.toString(false), 'http://go.microsoft.com/fwlink/?LinkId=518008'); + assert.equal(uri.toString(true), 'http://go.microsoft.com/fwlink/?LinkId=518008'); assert.equal(uri.toString(), 'http://go.microsoft.com/fwlink/?LinkId%3D518008'); let uri2 = URI.parse(uri.toString()); @@ -362,7 +362,7 @@ suite('URI', () => { uri = URI.parse('http://go.microsoft.com/fwlink/?LinkId=518008&foö&ké¥=üü'); assert.equal(uri.query, 'LinkId=518008&foö&ké¥=üü'); - assert.equal(uri.toString(false), 'http://go.microsoft.com/fwlink/?LinkId=518008&foö&ké¥=üü'); + assert.equal(uri.toString(true), 'http://go.microsoft.com/fwlink/?LinkId=518008&foö&ké¥=üü'); assert.equal(uri.toString(), 'http://go.microsoft.com/fwlink/?LinkId%3D518008%26fo%C3%B6%26k%C3%A9%C2%A5%3D%C3%BC%C3%BC'); uri2 = URI.parse(uri.toString()); diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index cd4b831440f..7d103a920ad 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -928,21 +928,24 @@ declare namespace vscode { fragment: string; /** - * The string representing the corresponding file system path of this URI. + * The string representing the corresponding file system path of this Uri. * * Will handle UNC paths and normalize windows drive letters to lower-case. Also * uses the platform specific path separator. Will *not* validate the path for - * invalid characters and semantics. Will *not* look at the scheme of this URI. + * invalid characters and semantics. Will *not* look at the scheme of this Uri. */ fsPath: string; /** - * Returns a canonical representation of this URI. The representation and normalization - * of a URI depends on the scheme. + * Returns a string representation of this Uri. The representation and normalization + * of a URI depends on the scheme. The resulting string can be safely used with + * [Uri.parse](#Uri.parse). * - * @returns A string that is the encoded version of this Uri. + * @param skipEncoding Do not percentage-encode the result, defaults to `false`. Note that + * the `#` and `?` characters occuring in the path will always be encoded. + * @returns A string representation of this Uri. */ - toString(): string; + toString(skipEncoding?: boolean): string; /** * Returns a JSON representation of this Uri. diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index 2a526bbb4d2..9a3601f53f7 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -136,7 +136,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { if (resourceInput.resource instanceof URI) { let schema = resourceInput.resource.scheme; if (schema === network.Schemas.http || schema === network.Schemas.https) { - window.open(resourceInput.resource.toString(false)); + window.open(resourceInput.resource.toString(true)); return TPromise.as(null); } } -- GitLab