tlrobinson / narwhal

[DEPRECATED] A JavaScript standard library, package manager, and more.
http://narwhaljs.org/
372 stars 16 forks source link

FILE.glob broken for windows absolute paths #96

Closed culbert closed 14 years ago

culbert commented 14 years ago

Was trying to use Jake to install jack-servlet and found that * and \ patterns were not being expanded.

Found that problem was that on line 357 of file.js. There you check to see if the path is absolute. If it is, the code assumes that the first component of the split path is empty because it incorrectly assumes the first character is '/'. The code then applies a "fixup" as follows.

if (exports.isAbsolute(pattern))
{
    paths = ["/"];
    parts.shift();
}

This then fails miserably on windows (though the isAbsolute does the right, os-specific, thing...).

The "solution" that I implemented to get on was to replace the above snippet with:

    if (exports.isAbsolute(pattern))
    {
        paths = parts[0] === '' ? ["/"] : [parts[0]];
        parts.shift();
    }

Cursory testing implies that this works (though there may be other, similar issues elsewhere).

I'm new to this code and git so apologies if the following is not in the desired format:

SHA1 ID of my copy: c5e8588b8902db248a32592dc2286bc9feeae70d

Patch:


@@ -354,7 +354,7 @@ exports.glob = function (pattern, flags) {

     if (exports.isAbsolute(pattern))
     {
-        paths = ["/"];
+        paths = parts[0] === '' ? ["/"] : [parts[0]];
         parts.shift();
     }

tlrobinson commented 14 years ago

Thanks. I've merged it in.