glob-to-regexp
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -39,3 +39,2 @@ module.exports = function (glob, opts) { | ||
switch (c) { | ||
case "\\": | ||
case "/": | ||
@@ -111,7 +110,7 @@ case "$": | ||
// it's a globstar, so match zero or more path segments | ||
reStr += "(?:[^/]*(?:\/|$))*"; | ||
reStr += "((?:[^/]*(?:\/|$))*)"; | ||
i++; // move over the "/" | ||
} else { | ||
// it's not a globstar, so only match one path segment | ||
reStr += "[^/]*"; | ||
reStr += "([^/]*)"; | ||
} | ||
@@ -118,0 +117,0 @@ } |
{ | ||
"name": "glob-to-regexp", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Convert globs to regular expressions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
20
test.js
@@ -50,5 +50,9 @@ var globToRegexp = require("./index.js"); | ||
var testStr = "\\/$^+?.()=!|{},[].*" | ||
assertMatch(testStr, testStr); | ||
assertMatch(testStr, testStr, { flags: 'g' }); | ||
// Test string "\\\\/$^+?.()=!|{},[].*" represents <glob>\\/$^+?.()=!|{},[].*</glob> | ||
// The equivalent regex is: /^\\\/\$\^\+\?\.\(\)\=\!\|\{\}\,\[\]\..*$/ | ||
// Both glob and regex match: \/$^+?.()=!|{},[].* | ||
var testStr = "\\\\/$^+?.()=!|{},[].*"; | ||
var targetStr = "\\/$^+?.()=!|{},[].*"; | ||
assertMatch(testStr, targetStr); | ||
assertMatch(testStr, targetStr, { flags: 'g' }); | ||
@@ -158,5 +162,9 @@ // Equivalent matches without/with using RegExp 'g' | ||
// Remaining special chars should still match themselves | ||
var testExtStr = "\\/$^+.()=!|,.*" | ||
assertMatch(testExtStr, testExtStr, { extended: true }); | ||
assertMatch(testExtStr, testExtStr, { extended: true, globstar: globstar, flags: 'g' }); | ||
// Test string "\\\\/$^+.()=!|,.*" represents <glob>\\/$^+.()=!|,.*</glob> | ||
// The equivalent regex is: /^\\\/\$\^\+\.\(\)\=\!\|\,\..*$/ | ||
// Both glob and regex match: \/$^+.()=!|,.* | ||
var testExtStr = "\\\\/$^+.()=!|,.*"; | ||
var targetExtStr = "\\/$^+.()=!|,.*"; | ||
assertMatch(testExtStr, targetExtStr, { extended: true }); | ||
assertMatch(testExtStr, targetExtStr, { extended: true, globstar: globstar, flags: 'g' }); | ||
} | ||
@@ -163,0 +171,0 @@ |
18091
312