mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 14:01:38 +01:00
Revert "more strict (and correct) URI.file, #34449"
This reverts commit bcd8181238.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user