提交 3bf2afdc 编写于 作者: J Johannes Rieken

add TernarySearchTree#forUri2 which allow correct path casing handling,...

add TernarySearchTree#forUri2 which allow correct path casing handling, https://github.com/microsoft/vscode/issues/110241
上级 21c84a43
......@@ -140,7 +140,7 @@ export class UriIterator implements IKeyIterator<URI> {
private _states: UriIteratorState[] = [];
private _stateIdx: number = 0;
constructor(private readonly _ignorePathCasing: boolean | undefined) { }
constructor(private readonly _ignorePathCasing: (uri: URI) => boolean) { }
reset(key: URI): this {
this._value = key;
......@@ -152,10 +152,7 @@ export class UriIterator implements IKeyIterator<URI> {
this._states.push(UriIteratorState.Authority);
}
if (this._value.path) {
this._pathIterator = new PathIterator(false, this._ignorePathCasing === undefined
? key.scheme === Schemas.file && isLinux
: !this._ignorePathCasing
);
this._pathIterator = new PathIterator(false, !this._ignorePathCasing(key));
this._pathIterator.reset(key.path);
if (this._pathIterator.value()) {
this._states.push(UriIteratorState.Path);
......@@ -231,7 +228,14 @@ class TernarySearchTreeNode<K, V> {
export class TernarySearchTree<K, V> {
/**
* @deprecated
*/
static forUris<E>(ignorePathCasing?: boolean): TernarySearchTree<URI, E> {
return new TernarySearchTree<URI, E>(new UriIterator(key => ignorePathCasing ?? (key.scheme === Schemas.file && isLinux)));
}
static forUris2<E>(ignorePathCasing: (key: URI) => boolean): TernarySearchTree<URI, E> {
return new TernarySearchTree<URI, E>(new UriIterator(ignorePathCasing));
}
......
......@@ -368,7 +368,7 @@ suite('Map', () => {
});
test('URIIterator', function () {
const iter = new UriIterator(false);
const iter = new UriIterator(() => false);
iter.reset(URI.parse('file:///usr/bin/file.txt'));
assert.equal(iter.value(), 'file');
......@@ -680,7 +680,7 @@ suite('Map', () => {
});
test('TernarySearchTree (URI) - basics', function () {
let trie = new TernarySearchTree<URI, number>(new UriIterator(false));
let trie = new TernarySearchTree<URI, number>(new UriIterator(() => false));
trie.set(URI.file('/user/foo/bar'), 1);
trie.set(URI.file('/user/foo'), 2);
......@@ -700,7 +700,7 @@ suite('Map', () => {
test('TernarySearchTree (URI) - lookup', function () {
const map = new TernarySearchTree<URI, number>(new UriIterator(false));
const map = new TernarySearchTree<URI, number>(new UriIterator(() => false));
map.set(URI.parse('http://foo.bar/user/foo/bar'), 1);
map.set(URI.parse('http://foo.bar/user/foo?query'), 2);
map.set(URI.parse('http://foo.bar/user/foo?QUERY'), 3);
......@@ -715,9 +715,19 @@ suite('Map', () => {
assert.equal(map.get(URI.parse('http://foo.bar/user/foo/bar/boo')), undefined);
});
test('TernarySearchTree (URI) - lookup, casing', function () {
const map = new TernarySearchTree<URI, number>(new UriIterator(uri => /^https?$/.test(uri.scheme)));
map.set(URI.parse('http://foo.bar/user/foo/bar'), 1);
assert.equal(map.get(URI.parse('http://foo.bar/USER/foo/bar')), 1);
map.set(URI.parse('foo://foo.bar/user/foo/bar'), 1);
assert.equal(map.get(URI.parse('foo://foo.bar/USER/foo/bar')), undefined);
});
test('TernarySearchTree (PathSegments) - superstr', function () {
const map = new TernarySearchTree<URI, number>(new UriIterator(false));
const map = new TernarySearchTree<URI, number>(new UriIterator(() => false));
map.set(URI.file('/user/foo/bar'), 1);
map.set(URI.file('/user/foo'), 2);
map.set(URI.file('/user/foo/flip/flop'), 3);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册