Skip to content

Commit

Permalink
make windows paths case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisblossom committed Jul 4, 2019
1 parent 69364ed commit c60796c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path';
import test from 'ava';
import isPathInside from '.';

Expand All @@ -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});
});

0 comments on commit c60796c

Please sign in to comment.