Skip to content

Commit

Permalink
#59: fixes trailing backslashes before ]
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelzhang committed May 22, 2020
1 parent 8a8d44a commit 05780f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v1
Expand Down
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -40,6 +40,12 @@ const sanitizeRange = range => range.replace(
: EMPTY
)

// See fixtures #59
const cleanRangeBackSlash = slashes => slashes.slice(
0,
parseInt(slashes.length / 2, 10) * 2
)

// > If the pattern ends with a slash,
// > it is removed for the purpose of the following description,
// > but it would only find a match with a directory.
Expand Down Expand Up @@ -217,7 +223,7 @@ const REPLACERS = [
/(\\)?\[([^\]/]*?)(\\*)($|\])/g,
(match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE
// '\\[bar]' -> '\\\\[bar\\]'
? `\\[${range}${close}`
? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`
: close === ']'
? endEscape.length % 2 === 0
// A normal case, and it is a range notation
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/cases.js
Expand Up @@ -23,12 +23,12 @@ const cases = [
[
'#59 and more cases about range notation',
[
'src/\\[foo\\]',
'src/\\[foo2\\\\]',
'src/\\[foo3\\\\\\]',
'src/\\[foo4\\\\\\\\]',
'src/\\[foo5\\\\\\\\\\]',
'src/\\[foo6\\\\\\\\\\\\]',
'src/\\[foo\\]', // 1 -> 0
'src/\\[foo2\\\\]', // 2 -> 1
'src/\\[foo3\\\\\\]', // 3 -> 1
'src/\\[foo4\\\\\\\\]', // 4 -> 2
'src/\\[foo5\\\\\\\\\\]', // 5 -> 2
'src/\\[foo6\\\\\\\\\\\\]', // 6 -> 3

'src/\\[bar]',

Expand Down

0 comments on commit 05780f5

Please sign in to comment.