Skip to content

Commit

Permalink
5.0.4: fixes #47: fixes isPathValid in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelzhang committed Nov 3, 2018
1 parent 4d97791 commit 15de356
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
29 changes: 18 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,18 @@ class Ignore {
}
}

const factory = options => new Ignore(options)

const isPathValid = path => checkPath(path, returnFalse)


factory.isPathValid = isPathValid

// Fixes typescript
factory.default = factory

module.exports = factory

// Windows
// --------------------------------------------------------------
/* istanbul ignore if */
Expand All @@ -546,22 +558,17 @@ if (
const test = Ignore.prototype._test

/* eslint no-control-regex: "off" */
const make_posix = str => /^\\\\\?\\/.test(str)
const makePosix = str => /^\\\\\?\\/.test(str)
|| /["<>|\u0000-\u001F]+/u.test(str)
? str
: str.replace(/\\/g, '/')

Ignore.prototype._test = function testWin32 (path, ...args) {
path = make_posix(path)
path = makePosix(path)
return test.call(this, path, ...args)
}
}

const factory = options => new Ignore(options)

factory.isPathValid = path => checkPath(path, returnFalse)

// Fixes typescript
factory.default = factory

module.exports = factory
factory.isPathValid = path => path
? isPathValid(makePosix(path))
: isPathValid(path)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ignore",
"version": "5.0.3",
"version": "5.0.4",
"description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.",
"files": [
"legacy.js",
Expand Down
31 changes: 23 additions & 8 deletions test/others.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const ignore = require('..')

const {isPathValid} = ignore

const IS_WINDOWS = process.platform === 'win32'
const SHOULD_TEST_WINDOWS = process.env.IGNORE_TEST_WIN32
|| IS_WINDOWS

test('.add(<Ignore>)', t => {
const a = ignore().add(['.abc/*', '!.abc/d/'])
const b = ignore().add(a).add('!.abc/e/')
Expand Down Expand Up @@ -97,15 +101,26 @@ test('special case: invalid paths, throw', t => {
})

test('isPathValid', t => {
const paths = [
'.',
'./foo',
'../foo',
'/foo',
false,
'foo'
]

if (SHOULD_TEST_WINDOWS) {
paths.push(
'..\\foo',
'.\\foo',
'\\foo',
'\\\\foo'
)
}

t.deepEqual(
[
'.',
'./foo',
'../foo',
'/foo',
false,
'foo'
].filter(isPathValid),
paths.filter(isPathValid),
[
'foo'
]
Expand Down

0 comments on commit 15de356

Please sign in to comment.