diff --git a/src/fs.ts b/src/fs.ts index 924900488..ad00f2e4c 100644 --- a/src/fs.ts +++ b/src/fs.ts @@ -78,7 +78,7 @@ export class LocalFileSystem implements FileSystem { follow: true, }) globber.on('match', (file: string) => { - subscriber.next(normalizeUri(base + file)) + subscriber.next(file) }) globber.on('error', (err: any) => { subscriber.error(err) @@ -89,6 +89,12 @@ export class LocalFileSystem implements FileSystem { return () => { globber.abort() } + }).map(file => { + const encodedPath = file + .split('/') + .map(encodeURIComponent) + .join('/') + return normalizeUri(base + encodedPath) }) } diff --git a/src/test/memfs.test.ts b/src/test/memfs.test.ts index c5ed629bb..4e64881a0 100644 --- a/src/test/memfs.test.ts +++ b/src/test/memfs.test.ts @@ -18,6 +18,14 @@ describe('memfs.ts', () => { sinon.assert.calledOnce(listener) sinon.assert.calledWithExactly(listener, 'file:///foo/bar.txt', undefined) }) + it('should add just a URI and emit an event when URI has encoded char', () => { + const listener = sinon.spy() + const fs = new InMemoryFileSystem('/') + fs.on('add', listener) + fs.add('file:///foo/%25bar.txt') + sinon.assert.calledOnce(listener) + sinon.assert.calledWithExactly(listener, 'file:///foo/%25bar.txt', undefined) + }) it('should add content for a URI and emit an event', () => { const listener = sinon.spy() const fs = new InMemoryFileSystem('/')