Skip to content

Commit

Permalink
fix: do not match braces when they start with the dollar sign ($)
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Jul 24, 2021
1 parent 9fa3328 commit 33ffe9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/validateConfig.js
Expand Up @@ -23,13 +23,14 @@ const TEST_DEPRECATED_KEYS = new Map([
* two curly braces without a `,` or `..` between them, to make sure
* users can still accidentally use them without
* some linters never matching anything. It will further not match
* escaped braces `\{` `\}`, or if braces contain an escaped comma `\,`
* escaped braces `\{` `\}`, or if braces contain an escaped comma `\,`.
* Finally, a dollar sign `${` inhibits brace expansion.
*
* For example `.{js,ts}` or `file_{1..10}` are valid but `*.{js}` is not.
*
* @see https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
*/
const BRACES_REGEXP = new RegExp(/(?<!\\)({)(?:(?!(?<!\\),|\.\.).)*?(?<!\\)(})/g)
const BRACES_REGEXP = new RegExp(/(?<![\\$])({)(?:(?!(?<!\\),|\.\.).)*?(?<!\\)(})/g)

/**
* Remove braces from incorrect glob patterns.
Expand Down
4 changes: 4 additions & 0 deletions test/validateConfig.spec.js
Expand Up @@ -19,6 +19,10 @@ describe('BRACES_REGEXP', () => {
expect('*.{js\\,ts}'.match(BRACES_REGEXP)).toBeTruthy()
})

it("should not match '*.${js}'", () => {
expect('*.${js}'.match(BRACES_REGEXP)).not.toBeTruthy()
})

it(`should not match '.{js,ts}'`, () => {
expect('.{js,ts}'.match(BRACES_REGEXP)).not.toBeTruthy()
})
Expand Down

0 comments on commit 33ffe9c

Please sign in to comment.