From 7f30f135438f45f62a373d551764f0e804ff62ed Mon Sep 17 00:00:00 2001 From: Adam Luikart Date: Sat, 25 Jun 2011 17:37:57 -0500 Subject: [PATCH] Update POSIX splitPathRe to allow control chars. Fixes #1230. Use [\s\S] instead of . to match any char, including newlines. --- lib/path.js | 2 +- test/simple/test-path.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/path.js b/lib/path.js index 59fc5b32163..576b12f1e6d 100644 --- a/lib/path.js +++ b/lib/path.js @@ -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 diff --git a/test/simple/test-path.js b/test/simple/test-path.js index 734fcaf2cf1..3d72ad733e7 100644 --- a/test/simple/test-path.js +++ b/test/simple/test-path.js @@ -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');