提交 65cb3397 编写于 作者: J Johannes Rieken

flip boolean, expose `skipEncoding` in API

上级 4e5950f1
......@@ -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;
......
......@@ -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());
......
......@@ -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.
......
......@@ -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<IEditor>(null);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册