diff --git a/src/__tests__/normalize.spec.ts b/src/__tests__/normalize.spec.ts index 332ebf5..6f2c2e6 100644 --- a/src/__tests__/normalize.spec.ts +++ b/src/__tests__/normalize.spec.ts @@ -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 diff --git a/src/__tests__/startsWithWindowsDrive.spec.ts b/src/__tests__/startsWithWindowsDrive.spec.ts index 5c03cc4..bc2dca1 100644 --- a/src/__tests__/startsWithWindowsDrive.spec.ts +++ b/src/__tests__/startsWithWindowsDrive.spec.ts @@ -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); diff --git a/src/grammar.pegjs b/src/grammar.pegjs index eb9072b..c093859 100644 --- a/src/grammar.pegjs +++ b/src/grammar.pegjs @@ -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 } }