From c60796cd719407cd83614985f66236efa2112ee6 Mon Sep 17 00:00:00 2001 From: Chris Blossom Date: Tue, 2 Jul 2019 19:24:49 -0700 Subject: [PATCH] make windows paths case-insensitive --- index.js | 5 +++++ test.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/index.js b/index.js index 96892be..78a1979 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,11 @@ module.exports = (childPath, parentPath) => { childPath = path.resolve(childPath); parentPath = path.resolve(parentPath); + if (process.platform === 'win32') { + childPath = childPath.toLowerCase(); + parentPath = parentPath.toLowerCase(); + } + if (childPath === parentPath) { return false; } diff --git a/test.js b/test.js index 8d1d464..8295377 100644 --- a/test.js +++ b/test.js @@ -1,3 +1,4 @@ +import path from 'path'; import test from 'ava'; import isPathInside from '.'; @@ -7,3 +8,19 @@ test('main', t => { t.false(isPathInside('a/b', 'a/b')); t.false(isPathInside('/a/b', '/a/b')); }); + +test('win32', t => { + const processPlatform = process.platform; + const pathSep = path.sep; + + Object.defineProperty(process, 'platform', {value: 'win32'}); + Object.defineProperty(path, 'sep', {value: '\\'}); + + t.true(isPathInside('A\\b\\c', 'a\\b')); + t.false(isPathInside('A\\b', 'a\\b')); + t.true(isPathInside('c:\\a\\b\\c\\d', 'C:\\a\\b\\c')); + t.false(isPathInside('C:\\a\\b\\c', 'c:\\a\\b\\c')); + + Object.defineProperty(process, 'platform', {value: processPlatform}); + Object.defineProperty(path, 'sep', {value: pathSep}); +});