Skip to content

Commit

Permalink
fix: recognize windows drive letters with a leading slash, like '/C:/' (
Browse files Browse the repository at this point in the history
#21)

* fix: normalize '/C:/' to lowercase since we do that for 'C:/'

* two more tests
  • Loading branch information
billiegoose authored Jul 29, 2020
1 parent 208fd8c commit 3b5dc04
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/__tests__/normalize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ describe('normalize', () => {
});
});

describe('normalizes capitalization of Windows drive letters', () => {
it.each`
path | result
${'C:\\foo\\bar'} | ${'c:/foo/bar'}
${'/C:/foo/bar'} | ${'c:/foo/bar'}
${'file:///C:/foo/bar'} | ${'c:/foo/bar'}
${'file://C:/foo/bar'} | ${'c:/foo/bar'}
`("normalize('$path')", ({ path, result }) => {
expect(normalize(path)).toEqual(result);
});
});

describe('ignores POSIX slashes', () => {
it.each`
path | result
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/startsWithWindowsDrive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { startsWithWindowsDrive } from '../';

describe('startsWithWindowsDrive', () => {
it.each(['c:\\foo\\bar.json', 'c:\\', 'c:/', 'c:/foo/bar.json', 'c:\\', 'Z:\\', 'A:/'])(
it.each(['c:\\foo\\bar.json', 'c:\\', 'c:/', 'c:/', '/C:/', '/C:\\', 'c:/foo/bar.json', 'c:\\', 'Z:\\', 'A:/'])(
'recognizes driver letter in %s',
filepath => {
expect(startsWithWindowsDrive(filepath)).toBe(true);
Expand Down
16 changes: 8 additions & 8 deletions src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ AbsolutePath
}

Root
= PosixRoot
/ WindowsRoot
= WindowsRoot
/ PosixRoot

PosixRoot
= Sep {
WindowsRoot
= Sep ? drive:[A-Za-z] ":" Sep {
return {
drive: null
drive: drive.toLowerCase() + ':'
}
}

WindowsRoot
= drive:[A-Za-z] ":" Sep {
PosixRoot
= Sep {
return {
drive: drive.toLowerCase() + ':'
drive: null
}
}

Expand Down

0 comments on commit 3b5dc04

Please sign in to comment.