Permalink
Browse files

Fix the ends_with() function and the check for a file name being the …

…last component of a path in find_module().
  • Loading branch information...
1 parent 84943d0 commit 924b5e0cfd68cc3f9234129f0ddd1a26f86cabd1 @dhruvbird committed Oct 18, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/dutil.js
View
@@ -352,11 +352,13 @@ function time_diff(past, present) {
}
function ends_with(haystack, needle) {
- /* Checks whether the string needle ends with the string
- * haystack
+ /* Checks whether the string haystack ends with the string
+ * needle
*
*/
- return haystack.search(needle) !== -1;
+ return (needle.length <= haystack.length ?
+ haystack.substring(haystack.length - needle.length) === needle :
+ false);
}
function find_module(file_name) {
@@ -373,7 +375,7 @@ function find_module(file_name) {
var mname;
for (mname in require.cache) {
if (require.cache.hasOwnProperty(mname)) {
- if (ends_with(mname, file_name)) {
+ if (ends_with(mname, "/" + file_name)) {
mhandle.handle = require.cache[mname].exports;
mhandle.key = mname;
break;

0 comments on commit 924b5e0

Please sign in to comment.