From e8a6fea08cd3f0efc8e04a223a4f1e2d57fe8d4e Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 15 Sep 2017 16:33:05 +0200 Subject: [PATCH] Revert "more strict (and correct) URI.file, #34449" This reverts commit bcd81812382b5385ad647e2d612e50237bcd50e5. --- src/vs/base/common/uri.ts | 15 +++------- src/vs/base/test/common/uri.test.ts | 44 +++++++++++++---------------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/vs/base/common/uri.ts b/src/vs/base/common/uri.ts index 4dfeff378ee..39ad9e80805 100644 --- a/src/vs/base/common/uri.ts +++ b/src/vs/base/common/uri.ts @@ -56,7 +56,6 @@ export default class URI { private static _empty = ''; private static _slash = '/'; private static _regexp = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/; - private static _driveLetter = /^[a-zA-Z]:/; private static _driveLetterPath = /^\/[a-zA-Z]:/; private static _upperCaseDrive = /^(\/)?([A-Z]:)/; @@ -213,25 +212,19 @@ export default class URI { let idx = path.indexOf(URI._slash, 2); if (idx === -1) { authority = path.substring(2); - path = URI._slash; + path = URI._empty; } else { authority = path.substring(2, idx); path = path.substring(idx); } } - // absolute windows paths get another slash - if (URI._driveLetter.test(path)) { + // Ensure that path starts with a slash + // or that it is at least a slash + if (path[0] !== URI._slash) { path = URI._slash + path; } - // path must be absolute because we cannot format them - // otherwise: `file:./foo` -> file://./foo -> `{ authority: '.', path: 'foo' }` - // https://tools.ietf.org/html/rfc8089#section-2 - else if (path[0] !== URI._slash) { - throw new Error('[UriError]: relative paths are not supported.'); - } - return new URI('file', authority, path, URI._empty, URI._empty); } diff --git a/src/vs/base/test/common/uri.test.ts b/src/vs/base/test/common/uri.test.ts index df2d989d26c..3341b0bcb6a 100644 --- a/src/vs/base/test/common/uri.test.ts +++ b/src/vs/base/test/common/uri.test.ts @@ -38,11 +38,13 @@ suite('URI', () => { assert.equal(URI.file('c:/win/path/').fsPath, 'c:\\win\\path\\'); assert.equal(URI.file('C:/win/path').fsPath, 'c:\\win\\path'); assert.equal(URI.file('/c:/win/path').fsPath, 'c:\\win\\path'); + assert.equal(URI.file('./c/win/path').fsPath, '\\.\\c\\win\\path'); } else { assert.equal(URI.file('c:/win/path').fsPath, 'c:/win/path'); assert.equal(URI.file('c:/win/path/').fsPath, 'c:/win/path/'); assert.equal(URI.file('C:/win/path').fsPath, 'c:/win/path'); assert.equal(URI.file('/c:/win/path').fsPath, 'c:/win/path'); + assert.equal(URI.file('./c/win/path').fsPath, '/./c/win/path'); } }); @@ -316,12 +318,27 @@ suite('URI', () => { test('URI#file, no path-is-uri check', () => { // we don't complain here - let value = URI.file('/file://path/to/file'); + let value = URI.file('file://path/to/file'); assert.equal(value.scheme, 'file'); assert.equal(value.authority, ''); assert.equal(value.path, '/file://path/to/file'); }); + test('URI#file, always slash', () => { + + var value = URI.file('a.file'); + assert.equal(value.scheme, 'file'); + assert.equal(value.authority, ''); + assert.equal(value.path, '/a.file'); + assert.equal(value.toString(), 'file:///a.file'); + + value = URI.parse(value.toString()); + assert.equal(value.scheme, 'file'); + assert.equal(value.authority, ''); + assert.equal(value.path, '/a.file'); + assert.equal(value.toString(), 'file:///a.file'); + }); + test('URI.toString, only scheme and query', () => { var value = URI.parse('stuff:?qüery'); assert.equal(value.toString(), 'stuff:?q%C3%BCery'); @@ -410,36 +427,13 @@ suite('URI', () => { assert.equal(uri.toString(true), 'https://twitter.com/search?src=typd&q=%23tag'); }); - test('class URI cannot represent relative file paths, #34449', function () { - const uri = URI.parse('file:./relative/path'); - assert.equal(uri.scheme, 'file'); - assert.equal(uri.authority, ''); - assert.equal(uri.path, './relative/path'); - - assert.equal(uri.toString(), 'file://./relative/path'); - - // this is asymetric to be spec-compliant - const uri2 = URI.parse(uri.toString()); - assert.equal(uri2.authority, '.'); - assert.equal(uri2.path, '/relative/path'); - }); - - test('class URI cannot represent relative file paths, #34449', function () { - - const path = '/foo/bar'; - assert.equal(URI.file(path).path, path); - - // no relative paths - assert.throws(() => URI.file('foo/bar')); - assert.throws(() => URI.file('./foo/bar')); - }); test('URI - (de)serialize', function () { var values = [ URI.parse('http://localhost:8080/far'), URI.file('c:\\test with %25\\c#code'), - URI.file('//shäres/path/c#/plugin.json'), + URI.file('\\\\shäres\\path\\c#\\plugin.json'), URI.parse('http://api/files/test.me?t=1234'), URI.parse('http://api/files/test.me?t=1234#fff'), URI.parse('http://api/files/test.me#fff'),