Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 322dbe7

Browse files
committed
fix(serve): encode glob returned path.
Close #422.
1 parent 7bda4cb commit 322dbe7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/fs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ export class LocalFileSystem implements FileSystem {
7878
follow: true,
7979
})
8080
globber.on('match', (file: string) => {
81-
subscriber.next(normalizeUri(base + file))
81+
const encodedPath = file
82+
.split('/')
83+
.map(encodeURIComponent)
84+
.join('/')
85+
subscriber.next(normalizeUri(base + encodedPath))
8286
})
8387
globber.on('error', (err: any) => {
8488
subscriber.error(err)

src/test/memfs.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ describe('memfs.ts', () => {
1818
sinon.assert.calledOnce(listener)
1919
sinon.assert.calledWithExactly(listener, 'file:///foo/bar.txt', undefined)
2020
})
21+
it('should add just a URI and emit an event when URI has encoded char', () => {
22+
const listener = sinon.spy()
23+
const fs = new InMemoryFileSystem('/')
24+
fs.on('add', listener)
25+
fs.add('file:///foo/%25bar.txt')
26+
sinon.assert.calledOnce(listener)
27+
sinon.assert.calledWithExactly(listener, 'file:///foo/%25bar.txt', undefined)
28+
})
2129
it('should add content for a URI and emit an event', () => {
2230
const listener = sinon.spy()
2331
const fs = new InMemoryFileSystem('/')

0 commit comments

Comments
 (0)