Update POSIX splitPathRe to allow control chars. Fixes #1230.

Use [\s\S] instead of . to match any char, including newlines.
This commit is contained in:
Adam Luikart 2011-06-25 17:37:57 -05:00 committed by Ben Noordhuis
parent 04c9169892
commit 7f30f13543
2 changed files with 9 additions and 1 deletions

View File

@ -249,7 +249,7 @@ if (isWindows) {
// Regex to split a filename into [*, dir, basename, ext]
// posix version
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
var splitPathRe = /^([\s\S]+\/(?!$)|\/)?((?:[\s\S]+?)?(\.[^.]*)?)$/;
// path.resolve([from ...], to)
// posix version

View File

@ -30,6 +30,14 @@ var f = __filename;
assert.equal(path.basename(f), 'test-path.js');
assert.equal(path.basename(f, '.js'), 'test-path');
// POSIX filenames may include control characters
// c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html
if (!isWindows) {
var controlCharFilename = 'Icon' + String.fromCharCode(13);
assert.equal(path.basename('/a/b/' + controlCharFilename), controlCharFilename);
}
assert.equal(path.extname(f), '.js');
assert.equal(path.dirname(f).substr(-11), isWindows ? 'test\\simple' : 'test/simple');
assert.equal(path.dirname('/a/b/'), '/a');