Created
July 28, 2013 03:01
-
-
Save konobi/6097192 to your computer and use it in GitHub Desktop.
update to node-mocked to reflect reality better... uses a kinda hacky method, but should work.
This file contains hidden or 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
diff --git a/lib/index.js b/lib/index.js | |
index e3fde1b..5dd58ae 100644 | |
--- a/lib/index.js | |
+++ b/lib/index.js | |
@@ -22,8 +22,15 @@ module = module.exports = function (mock_path, libs){ | |
var new_path = path; | |
var foo = libs.filter(function(libname){ | |
- // XXX - this check may not be sufficient =0( | |
- return path.match(new RegExp(libname+'$')); | |
+ // NB - We need a lookbehind assertion here, which JS | |
+ // doesn't support, but we can fake using reversed | |
+ // strings and lookahead... yes it's a mindwarp | |
+ var tmp_path = path.reverse(); | |
+ var tmp_libname = libname.reverse(); | |
+ | |
+ // In proper Regexp this would map to: | |
+ // '(?<=(?:^|/))' + libname + '$' | |
+ return tmp_path.match(new RegExp('^' + tmp_libname + '(?=(?:/|$)'); | |
}); | |
if(foo.length > 0) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment