Skip to content

Commit

Permalink
fix: respect path separators when resolving aliases (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 7, 2022
1 parent 9a65834 commit a718ebe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/utils.ts
Expand Up @@ -31,7 +31,7 @@ export function resolveAlias (path: string, aliases: Record<string, string>) {
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))
}
}
Expand Down
9 changes: 8 additions & 1 deletion test/utils.spec.ts
Expand Up @@ -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')
Expand All @@ -39,7 +46,7 @@ describe('alias', () => {

describe('filename', () => {
const files = {
// POSIX
// POSIX
'test.html': 'test',
'/temp/myfile.html': 'myfile',
'./myfile.html': 'myfile',
Expand Down

0 comments on commit a718ebe

Please sign in to comment.