Skip to content

Commit

Permalink
Update POSIX splitPathRe to allow control chars. Fixes nodejs#1230.
Browse files Browse the repository at this point in the history
Use [\s\S] instead of . to match any char, including newlines.
  • Loading branch information
adamesque committed Jun 25, 2011
1 parent c95da94 commit e829cd3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/path.js
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/simple/test-path.js
Expand Up @@ -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');
Expand Down

0 comments on commit e829cd3

Please sign in to comment.