mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
test: edge cases for map fs
This commit is contained in:
@@ -14,4 +14,13 @@ describe('MapFS', () => {
|
||||
it('should resolve exceeding root', () => {
|
||||
expect(fs.resolve('foo/bar', '../../../coo', '')).toEqual('coo')
|
||||
})
|
||||
it('should resolve from absolute path', () => {
|
||||
expect(fs.resolve('/foo/bar', '../../coo', '')).toEqual('/coo')
|
||||
})
|
||||
it('should resolve exceeding root from absolute path', () => {
|
||||
expect(fs.resolve('/foo/bar', '../../../coo', '')).toEqual('/coo')
|
||||
})
|
||||
it('should resolve from invalid path', () => {
|
||||
expect(fs.resolve('foo//bar', '../coo', '')).toEqual('foo/coo')
|
||||
})
|
||||
})
|
||||
|
||||
+4
-2
@@ -32,10 +32,12 @@ export class MapFS {
|
||||
resolve (dir: string, file: string, ext: string) {
|
||||
file += ext
|
||||
if (dir === '.') return file
|
||||
const segments = dir.split(this.sep)
|
||||
const segments = dir.split(/\/+/)
|
||||
for (const segment of file.split(this.sep)) {
|
||||
if (segment === '.' || segment === '') continue
|
||||
else if (segment === '..') segments.pop()
|
||||
else if (segment === '..') {
|
||||
if (segments.length > 1 || segments[0] !== '') segments.pop()
|
||||
}
|
||||
else segments.push(segment)
|
||||
}
|
||||
return segments.join(this.sep)
|
||||
|
||||
Reference in New Issue
Block a user