### path.extname(p)
-Return the extension of the path. Everything after the last '.', if there
-is no '.' then it returns an empty string. Examples:
+Return the extension of the path. Everything after the last '.' in the last portion
+of the path. If there is no '.' in the last portion of the path or the only '.' is
+the first character, then it returns an empty string. Examples:
path.extname('index.html')
// returns
};
exports.extname = function (path) {
- var index = path.lastIndexOf('.');
- return index < 0 ? '' : path.substring(index);
+ var dot = path.lastIndexOf('.'),
+ slash = path.lastIndexOf('/');
+ // The last dot must be in the last path component, and it (the last dot) must
+ // not start the last path component (i.e. be a dot that signifies a hidden
+ // file in UNIX).
+ return dot <= slash + 1 ? '' : path.substring(dot);
};
exports.exists = function (path, callback) {
assert.equal(path.dirname("/"), "/");
path.exists(f, function (y) { assert.equal(y, true) });
+assert.equal(path.extname(""), "");
+assert.equal(path.extname("/path/to/file"), "");
+assert.equal(path.extname("/path/to/file.ext"), ".ext");
+assert.equal(path.extname("/path.to/file.ext"), ".ext");
+assert.equal(path.extname("/path.to/file"), "");
+assert.equal(path.extname("/path.to/.file"), "");
+assert.equal(path.extname("/path.to/.file.ext"), ".ext");
+assert.equal(path.extname("/path/to/f.ext"), ".ext");
+assert.equal(path.extname("/path/to/..ext"), ".ext");
+assert.equal(path.extname("file"), "");
+assert.equal(path.extname("file.ext"), ".ext");
+assert.equal(path.extname(".file"), "");
+assert.equal(path.extname(".file.ext"), ".ext");
+assert.equal(path.extname("/file"), "");
+assert.equal(path.extname("/file.ext"), ".ext");
+assert.equal(path.extname("/.file"), "");
+assert.equal(path.extname("/.file.ext"), ".ext");
+assert.equal(path.extname(".path/file.ext"), ".ext");
+assert.equal(path.extname("file.ext.ext"), ".ext");
+assert.equal(path.extname("file."), ".");
+
assert.equal(path.join(".", "fixtures/b", "..", "/b/c.js"), "fixtures/b/c.js");
assert.equal(path.normalize("./fixtures///b/../b/c.js"), "fixtures/b/c.js");