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 3, 2019
1 parent 69364ed commit 40b4d6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
'use strict';
const path = require('path');
const os = require('os');
const pathIsInside = require('path-is-inside');

module.exports = (childPath, parentPath) => {
childPath = path.resolve(childPath);
parentPath = path.resolve(parentPath);

if (os.platform() === 'win32') {
childPath = childPath.toLowerCase();
parentPath = parentPath.toLowerCase();
}

if (childPath === parentPath) {
return false;
}
Expand Down
21 changes: 21 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os from 'os';
import path from 'path';
import test from 'ava';
import isPathInside from '.';

Expand All @@ -7,3 +9,22 @@ test('main', t => {
t.false(isPathInside('a/b', 'a/b'));
t.false(isPathInside('/a/b', '/a/b'));
});

test('win32', t => {
const osPlatform = os.platform;
const processPlatform = process.platform;
const pathSep = path.sep;

os.platform = () => 'win32';
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'));

os.platform = osPlatform;
Object.defineProperty(process, 'platform', {value: processPlatform});
Object.defineProperty(path, 'sep', {value: pathSep});
});

0 comments on commit 40b4d6d

Please sign in to comment.