Skip to content

Commit

Permalink
escape non-range dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Dec 12, 2016
1 parent c495312 commit 08b9f64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/compilers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module.exports = function(brackets) {
return this.emit('^', node);
}

if (/-/.test(inner) && !/(\d-\d|\w-\w)/.test(inner)) {
inner = inner.split('-').join('\\-');
}

var isNegated = inner.charAt(0) === '^';
// add slashes to negated brackets, per spec
if (isNegated && inner.indexOf('/') === -1) {
Expand Down
29 changes: 16 additions & 13 deletions test/wildmatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,34 @@ describe('original wildmatch', function() {
});

it('should support Additional tests, including some malformed wildmats', function() {
assert(!match.isMatch('$', '[ --]'));
assert(!match.isMatch('+', '[,-.]'));
assert(!match.isMatch('-', '[!a-'));
assert(!match.isMatch('-', '[[-\\]]'));
assert(!match.isMatch('-', '[\\-_]'));
assert(!match.isMatch('-', '[a-'));
assert(!match.isMatch('-.]', '[,-.]'));
assert(!match.isMatch('0', '[ --]'));
assert(!match.isMatch('2', '[\\1-\\3]'));
assert(!match.isMatch('4', '[\\1-\\3]'));
assert(!match.isMatch('5', '[--A]'));
assert(!match.isMatch('[', '[\\\\-^]'));
assert(!match.isMatch('[', '[]-a]'));
assert(!match.isMatch('\\', '[!\\\\]'));
assert(!match.isMatch('\\', '[[-\\]]'));
assert(!match.isMatch('\\', '[\\]'));
assert(!match.isMatch('\\', '[\\]]'));
assert(!match.isMatch('\\]', '[\\]]'));
assert(!match.isMatch('^', '[!]-a]'));
assert(!match.isMatch(']', '[\\\\-^]'));
assert(!match.isMatch('^', '[]-a]'));
assert(!match.isMatch('a[]b', 'a[]b'));
assert(!match.isMatch('ab', '[!'));
assert(!match.isMatch('ab', '[-'));
assert(!match.isMatch('ab', 'a[]b'));
assert(!match.isMatch('acrt', 'a[c-c]st'));
assert(!match.isMatch('G', '[A-\\\\]'));
assert(!match.isMatch('j', '[a-e-n]'));
assert(match.isMatch(' ', '[ --]'));
assert(match.isMatch('$', '[ --]'));
assert(match.isMatch(' ', '[-- ]'));
assert(match.isMatch(',', '[,]'));
assert(match.isMatch(',', '[\\\\,]'));
assert(match.isMatch('-', '[ --]'));
Expand All @@ -113,26 +119,21 @@ describe('original wildmatch', function() {
assert(match.isMatch('-', '[---]'));
assert(match.isMatch('-', '[--A]'));
assert(match.isMatch('-', '[-]'));
assert(match.isMatch('-', '[\\-_]'));
assert(match.isMatch('-', '[[-\\]]'));
assert(match.isMatch('-', '[a-e-n]'));
assert(match.isMatch('-b]', '[a-]b]'));
assert(match.isMatch('2', '[\\1-\\3]'));
assert(match.isMatch('3', '[\\1-\\3]'));
assert(match.isMatch('5', '[--A]'));
assert(match.isMatch('[', '[!]-a]'));
assert(match.isMatch('[', '[[-\\]]'));
assert(match.isMatch('\\', '[[-\\]]'));
assert(match.isMatch('\\', '[\\\\,]'));
assert(match.isMatch('\\', '[\\\\]'));
assert(match.isMatch(']', '[[-\\]]'));
assert(match.isMatch(']', '[\\\\-^]'));
assert(match.isMatch(']', '[\\]]'));
assert(match.isMatch('^', '[]-a]'));
assert(match.isMatch('^', '[!]-a]'));
assert(match.isMatch('^', '[a^bc]'));
assert(match.isMatch('a', '[!------]'));
assert(match.isMatch('ab[', 'ab['));
assert(match.isMatch('acrt', 'a[c-c]rt'));
assert(match.isMatch('G', '[A-\\\\]'));
});

it('should support Case-sensitivy features', function() {
Expand Down Expand Up @@ -168,9 +169,11 @@ describe('original wildmatch', function() {
});

it('should support Additional tests not found in the original wildmatch', function() {
assert(!match.isMatch('-', '[]-z]'));
assert(match.isMatch('-', '[]-z]'));
assert(match.isMatch('-', '[[:space:]-\\]]'));
assert(match.isMatch('c', '[[:space:]-z]'));
assert(match.isMatch('c', '[]-z]'));
assert(match.isMatch(']', '[[:space:]-\\]]'));
assert(!match.isMatch('[', '[[:space:]-\\]]'));
assert(!match.isMatch('c', '[[:space:]-z]'));
assert(!match.isMatch('c', '[]-z]'));
});
});

0 comments on commit 08b9f64

Please sign in to comment.