Update POSIX splitPathRe to allow control chars. Fixes #1230.
authorAdam Luikart <me@adamluikart.com>
Sat, 25 Jun 2011 22:37:57 +0000 (17:37 -0500)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 4 Jul 2011 20:50:27 +0000 (22:50 +0200)
Use [\s\S] instead of . to match any char, including newlines.

lib/path.js
test/simple/test-path.js

index 59fc5b3..576b12f 100644 (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
index 734fcaf..3d72ad7 100644 (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');