提交 e9ed5e19 编写于 作者: J Johannes Rieken

towards scheme-enforcement in URIs, related to #55891

上级 9b7c16e0
...@@ -12,6 +12,12 @@ const _singleSlashStart = /^\//; ...@@ -12,6 +12,12 @@ const _singleSlashStart = /^\//;
const _doubleSlashStart = /^\/\//; const _doubleSlashStart = /^\/\//;
function _validateUri(ret: URI): void { function _validateUri(ret: URI): void {
// // scheme, must be set
// if (!ret.scheme) {
// throw new Error('[UriError]: Scheme is missing.');
// }
// scheme, https://tools.ietf.org/html/rfc3986#section-3.1 // scheme, https://tools.ietf.org/html/rfc3986#section-3.1
// ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
if (ret.scheme && !_schemePattern.test(ret.scheme)) { if (ret.scheme && !_schemePattern.test(ret.scheme)) {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import URI from 'vs/base/common/uri';
function assertUrl(raw: string, scheme: string, domain: string, port: string, path: string, queryString: string, fragmentId: string): void {
// check for equivalent behaviour
const uri = URI.parse(raw);
assert.equal(uri.scheme, scheme);
assert.equal(uri.authority, port ? domain + ':' + port : domain);
assert.equal(uri.path, path);
assert.equal(uri.query, queryString);
assert.equal(uri.fragment, fragmentId);
}
suite('Network', () => {
test('urls', () => {
assertUrl('http://www.test.com:8000/this/that/theother.html?query=foo#hash',
'http', 'www.test.com', '8000', '/this/that/theother.html', 'query=foo', 'hash'
);
assertUrl('http://www.test.com:8000/this/that/theother.html?query=foo',
'http', 'www.test.com', '8000', '/this/that/theother.html', 'query=foo', ''
);
assertUrl('http://www.test.com:8000/this/that/theother.html#hash',
'http', 'www.test.com', '8000', '/this/that/theother.html', '', 'hash'
);
assertUrl('http://www.test.com:8000/#hash',
'http', 'www.test.com', '8000', '/', '', 'hash'
);
assertUrl('http://www.test.com:8000#hash',
'http', 'www.test.com', '8000', '/', '', 'hash'
);
assertUrl('http://www.test.com/#hash',
'http', 'www.test.com', '', '/', '', 'hash'
);
assertUrl('http://www.test.com#hash',
'http', 'www.test.com', '', '/', '', 'hash'
);
assertUrl('http://www.test.com:8000/this/that/theother.html',
'http', 'www.test.com', '8000', '/this/that/theother.html', '', ''
);
assertUrl('http://www.test.com:8000/',
'http', 'www.test.com', '8000', '/', '', ''
);
assertUrl('http://www.test.com:8000',
'http', 'www.test.com', '8000', '/', '', ''
);
assertUrl('http://www.test.com/',
'http', 'www.test.com', '', '/', '', ''
);
assertUrl('//www.test.com/',
'', 'www.test.com', '', '/', '', ''
);
assertUrl('//www.test.com:8000/this/that/theother.html?query=foo#hash',
'', 'www.test.com', '8000', '/this/that/theother.html', 'query=foo', 'hash'
);
assertUrl('//www.test.com/this/that/theother.html?query=foo#hash',
'', 'www.test.com', '', '/this/that/theother.html', 'query=foo', 'hash'
);
assertUrl('https://www.test.com:8000/this/that/theother.html?query=foo#hash',
'https', 'www.test.com', '8000', '/this/that/theother.html', 'query=foo', 'hash'
);
assertUrl('f12://www.test.com:8000/this/that/theother.html?query=foo#hash',
'f12', 'www.test.com', '8000', '/this/that/theother.html', 'query=foo', 'hash'
);
assertUrl('inmemory://model/0',
'inmemory', 'model', '', '/0', '', ''
);
assertUrl('file:///c/far/boo/file.cs', 'file', '', '', '/c/far/boo/file.cs', '', '');
});
});
...@@ -65,8 +65,6 @@ suite('URI', () => { ...@@ -65,8 +65,6 @@ suite('URI', () => {
assert.equal(URI.from({ scheme: 'http', authority: 'www.MSFT.com', path: '/my/path' }).toString(), 'http://www.msft.com/my/path'); assert.equal(URI.from({ scheme: 'http', authority: 'www.MSFT.com', path: '/my/path' }).toString(), 'http://www.msft.com/my/path');
assert.equal(URI.from({ scheme: 'http', authority: '', path: 'my/path' }).toString(), 'http:/my/path'); assert.equal(URI.from({ scheme: 'http', authority: '', path: 'my/path' }).toString(), 'http:/my/path');
assert.equal(URI.from({ scheme: 'http', authority: '', path: '/my/path' }).toString(), 'http:/my/path'); assert.equal(URI.from({ scheme: 'http', authority: '', path: '/my/path' }).toString(), 'http:/my/path');
assert.equal(URI.from({ scheme: '', authority: '', path: 'my/path' }).toString(), 'my/path');
assert.equal(URI.from({ scheme: '', authority: '', path: '/my/path' }).toString(), '/my/path');
//http://a-test-site.com/#test=true //http://a-test-site.com/#test=true
assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: 'test=true' }).toString(), 'http://a-test-site.com/?test%3Dtrue'); assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: 'test=true' }).toString(), 'http://a-test-site.com/?test%3Dtrue');
assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: '', fragment: 'test=true' }).toString(), 'http://a-test-site.com/#test%3Dtrue'); assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: '', fragment: 'test=true' }).toString(), 'http://a-test-site.com/#test%3Dtrue');
...@@ -75,7 +73,7 @@ suite('URI', () => { ...@@ -75,7 +73,7 @@ suite('URI', () => {
test('http#toString, encode=FALSE', () => { test('http#toString, encode=FALSE', () => {
assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: 'test=true' }).toString(true), 'http://a-test-site.com/?test=true'); assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: 'test=true' }).toString(true), 'http://a-test-site.com/?test=true');
assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: '', fragment: 'test=true' }).toString(true), 'http://a-test-site.com/#test=true'); assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: '', fragment: 'test=true' }).toString(true), 'http://a-test-site.com/#test=true');
assert.equal(URI.from({}).with({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(true), 'http:/api/files/test.me?t=1234'); assert.equal(URI.from({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(true), 'http:/api/files/test.me?t=1234');
var value = URI.parse('file://shares/pröjects/c%23/#l12'); var value = URI.parse('file://shares/pröjects/c%23/#l12');
assert.equal(value.authority, 'shares'); assert.equal(value.authority, 'shares');
...@@ -107,12 +105,12 @@ suite('URI', () => { ...@@ -107,12 +105,12 @@ suite('URI', () => {
test('with, changes', () => { test('with, changes', () => {
assert.equal(URI.parse('before:some/file/path').with({ scheme: 'after' }).toString(), 'after:some/file/path'); assert.equal(URI.parse('before:some/file/path').with({ scheme: 'after' }).toString(), 'after:some/file/path');
assert.equal(URI.from({}).with({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(), 'http:/api/files/test.me?t%3D1234'); assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(), 'http:/api/files/test.me?t%3D1234');
assert.equal(URI.from({}).with({ scheme: 'http', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'http:/api/files/test.me?t%3D1234'); assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'http', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'http:/api/files/test.me?t%3D1234');
assert.equal(URI.from({}).with({ scheme: 'https', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'https:/api/files/test.me?t%3D1234'); assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'https', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'https:/api/files/test.me?t%3D1234');
assert.equal(URI.from({}).with({ scheme: 'HTTP', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTP:/api/files/test.me?t%3D1234'); assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'HTTP', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTP:/api/files/test.me?t%3D1234');
assert.equal(URI.from({}).with({ scheme: 'HTTPS', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTPS:/api/files/test.me?t%3D1234'); assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'HTTPS', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTPS:/api/files/test.me?t%3D1234');
assert.equal(URI.from({}).with({ scheme: 'boo', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'boo:/api/files/test.me?t%3D1234'); assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'boo', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'boo:/api/files/test.me?t%3D1234');
}); });
test('with, remove components #8465', () => { test('with, remove components #8465', () => {
...@@ -186,34 +184,13 @@ suite('URI', () => { ...@@ -186,34 +184,13 @@ suite('URI', () => {
assert.equal(value.query, ''); assert.equal(value.query, '');
assert.equal(value.fragment, ''); assert.equal(value.fragment, '');
value = URI.parse('api/files/test'); value = URI.parse('foo:api/files/test');
assert.equal(value.scheme, ''); assert.equal(value.scheme, 'foo');
assert.equal(value.authority, ''); assert.equal(value.authority, '');
assert.equal(value.path, 'api/files/test'); assert.equal(value.path, 'api/files/test');
assert.equal(value.query, ''); assert.equal(value.query, '');
assert.equal(value.fragment, ''); assert.equal(value.fragment, '');
value = URI.parse('api');
assert.equal(value.scheme, '');
assert.equal(value.authority, '');
assert.equal(value.path, 'api');
assert.equal(value.query, '');
assert.equal(value.fragment, '');
value = URI.parse('/api/files/test');
assert.equal(value.scheme, '');
assert.equal(value.authority, '');
assert.equal(value.path, '/api/files/test');
assert.equal(value.query, '');
assert.equal(value.fragment, '');
value = URI.parse('?test');
assert.equal(value.scheme, '');
assert.equal(value.authority, '');
assert.equal(value.path, '');
assert.equal(value.query, 'test');
assert.equal(value.fragment, '');
value = URI.parse('file:?q'); value = URI.parse('file:?q');
assert.equal(value.scheme, 'file'); assert.equal(value.scheme, 'file');
assert.equal(value.authority, ''); assert.equal(value.authority, '');
...@@ -221,13 +198,6 @@ suite('URI', () => { ...@@ -221,13 +198,6 @@ suite('URI', () => {
assert.equal(value.query, 'q'); assert.equal(value.query, 'q');
assert.equal(value.fragment, ''); assert.equal(value.fragment, '');
value = URI.parse('#test');
assert.equal(value.scheme, '');
assert.equal(value.authority, '');
assert.equal(value.path, '');
assert.equal(value.query, '');
assert.equal(value.fragment, 'test');
value = URI.parse('file:#d'); value = URI.parse('file:#d');
assert.equal(value.scheme, 'file'); assert.equal(value.scheme, 'file');
assert.equal(value.authority, ''); assert.equal(value.authority, '');
......
...@@ -58,16 +58,16 @@ suite('Marker Service', () => { ...@@ -58,16 +58,16 @@ suite('Marker Service', () => {
test('changeOne override', () => { test('changeOne override', () => {
let service = new markerService.MarkerService(); let service = new markerService.MarkerService();
service.changeOne('far', URI.parse('/path/only.cs'), [randomMarkerData()]); service.changeOne('far', URI.parse('file:///path/only.cs'), [randomMarkerData()]);
assert.equal(service.read().length, 1); assert.equal(service.read().length, 1);
assert.equal(service.read({ owner: 'far' }).length, 1); assert.equal(service.read({ owner: 'far' }).length, 1);
service.changeOne('boo', URI.parse('/path/only.cs'), [randomMarkerData()]); service.changeOne('boo', URI.parse('file:///path/only.cs'), [randomMarkerData()]);
assert.equal(service.read().length, 2); assert.equal(service.read().length, 2);
assert.equal(service.read({ owner: 'far' }).length, 1); assert.equal(service.read({ owner: 'far' }).length, 1);
assert.equal(service.read({ owner: 'boo' }).length, 1); assert.equal(service.read({ owner: 'boo' }).length, 1);
service.changeOne('far', URI.parse('/path/only.cs'), [randomMarkerData(), randomMarkerData()]); service.changeOne('far', URI.parse('file:///path/only.cs'), [randomMarkerData(), randomMarkerData()]);
assert.equal(service.read({ owner: 'far' }).length, 2); assert.equal(service.read({ owner: 'far' }).length, 2);
assert.equal(service.read({ owner: 'boo' }).length, 1); assert.equal(service.read({ owner: 'boo' }).length, 1);
...@@ -76,13 +76,13 @@ suite('Marker Service', () => { ...@@ -76,13 +76,13 @@ suite('Marker Service', () => {
test('changeOne/All clears', () => { test('changeOne/All clears', () => {
let service = new markerService.MarkerService(); let service = new markerService.MarkerService();
service.changeOne('far', URI.parse('/path/only.cs'), [randomMarkerData()]); service.changeOne('far', URI.parse('file:///path/only.cs'), [randomMarkerData()]);
service.changeOne('boo', URI.parse('/path/only.cs'), [randomMarkerData()]); service.changeOne('boo', URI.parse('file:///path/only.cs'), [randomMarkerData()]);
assert.equal(service.read({ owner: 'far' }).length, 1); assert.equal(service.read({ owner: 'far' }).length, 1);
assert.equal(service.read({ owner: 'boo' }).length, 1); assert.equal(service.read({ owner: 'boo' }).length, 1);
assert.equal(service.read().length, 2); assert.equal(service.read().length, 2);
service.changeOne('far', URI.parse('/path/only.cs'), []); service.changeOne('far', URI.parse('file:///path/only.cs'), []);
assert.equal(service.read({ owner: 'far' }).length, 0); assert.equal(service.read({ owner: 'far' }).length, 0);
assert.equal(service.read({ owner: 'boo' }).length, 1); assert.equal(service.read({ owner: 'boo' }).length, 1);
assert.equal(service.read().length, 1); assert.equal(service.read().length, 1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册