forked from isaacs/minimatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with escaped '@' in patterns
For example, ```js minimatch('@', '\\@*') ``` was returns `false` when `true` expected Close: isaacs#110
- Loading branch information
Showing
2 changed files
with
58 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var tap = require('tap') | ||
var minimatch = require('../') | ||
|
||
// test all characters with codes in range [mincc,maxcc] | ||
var mincc = 0x20 | ||
var maxcc = 0xFF | ||
// except listed in exceptions array | ||
var exceptions = ['/', '\\'] | ||
var pre = 'x' // prepended to the testable character | ||
var post = 'y' // appended to the testable character | ||
|
||
function escapeChar (cc) { | ||
return '"\\u' + ('000' + cc.toString(16).toUpperCase()).substr(-4) + '"' | ||
} | ||
|
||
tap.test('escaping tests', function (t) { | ||
for (var cc = mincc; cc <= maxcc; ++cc) { | ||
var cp = String.fromCharCode(cc) | ||
if (exceptions.indexOf(cp) === -1) { | ||
var str = pre + cp + post | ||
var pattern = '*\\' + cp + '*' | ||
var msg = JSON.stringify(str) + | ||
' (for codepoint ' + escapeChar(cc) + ')' + | ||
' should match pattern ' + JSON.stringify(pattern) | ||
t.equal(minimatch(str, pattern), true, msg) | ||
} | ||
} | ||
t.end() | ||
}) | ||
|
||
tap.test('class escaping tests', function (t) { | ||
for (var cc = mincc; cc <= maxcc; ++cc) { | ||
var cp = String.fromCharCode(cc) | ||
if (exceptions.indexOf(cp) === -1) { | ||
var str = pre + cp + post | ||
var pattern = '*[\\' + cp + ']*' | ||
var msg = JSON.stringify(str) + | ||
' (for codepoint ' + escapeChar(cc) + ')' + | ||
' should match pattern ' + JSON.stringify(pattern) | ||
t.equal(minimatch(str, pattern), true, msg) | ||
} | ||
} | ||
t.end() | ||
}) |