diff --git a/src/utils.ts b/src/utils.ts index 2305ecd..3dedbdb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -31,7 +31,7 @@ export function resolveAlias (path: string, aliases: Record) { const _path = normalizeWindowsPath(path) aliases = normalizeAliases(aliases) for (const alias in aliases) { - if (_path.startsWith(alias)) { + if (_path.startsWith(alias) && pathSeparators.includes(_path[alias.length])) { return join(aliases[alias], _path.slice(alias.length)) } } diff --git a/test/utils.spec.ts b/test/utils.spec.ts index d97fd23..222e514 100644 --- a/test/utils.spec.ts +++ b/test/utils.spec.ts @@ -30,6 +30,13 @@ describe('alias', () => { expect(resolveAlias(from, aliases)).toBe(to) }) } + it('respects path separators', () => { + const aliases = { + '~': '/root', + '~assets': '/root/some/dir' + } + expect(resolveAlias('~assets/smth.jpg', aliases)).toMatchInlineSnapshot('"/root/some/dir/smth.jpg"') + }) it('unchanged', () => { expect(resolveAlias('foo/bar.js', aliases)).toBe('foo/bar.js') expect(resolveAlias('./bar.js', aliases)).toBe('./bar.js') @@ -39,7 +46,7 @@ describe('alias', () => { describe('filename', () => { const files = { - // POSIX + // POSIX 'test.html': 'test', '/temp/myfile.html': 'myfile', './myfile.html': 'myfile',