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

fix(serve): encode glob returned path. #469

Merged
merged 2 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})
}

Expand Down
8 changes: 8 additions & 0 deletions src/test/memfs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand Down