summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2015-05-11 12:11:01 -0400
committercjihrig <cjihrig@gmail.com>2015-05-13 10:16:44 -0400
commit76937051f852accd60c18b6a63277061d98d3909 (patch)
tree6bc343770038a54194025ee033750de197480bc4
parent966acb9916874da599c9641825b3eb154af0f32d (diff)
downloadnode-new-76937051f852accd60c18b6a63277061d98d3909.tar.gz
os: refine tmpdir() trailing slash stripping
os.tmpdir() began stripping trailing slashes in b57cc51d8d3f4ad279591ae8fa6584ee22773b97. This causes problems if the temp directory is simply '/'. It also stripped trailing slashes without first determining which slash type is used by the current operating system. This commit only strips trailing slashes if another character precedes the slash. On Windows, it checks for ':', as not to strip slashes from something like 'C:\'. It also only strips slashes that are appropriate for the user's operating system. Fixes: https://github.com/iojs/io.js/issues/1669 PR-URL: https://github.com/iojs/io.js/pull/1673 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Christian Tellnes <christian@tellnes.no>
-rw-r--r--lib/os.js5
-rw-r--r--test/parallel/test-os.js10
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/os.js b/lib/os.js
index cd4eb1c12f..4426612285 100644
--- a/lib/os.js
+++ b/lib/os.js
@@ -22,6 +22,9 @@ exports.platform = function() {
return process.platform;
};
+const trailingSlashRe = isWindows ? /[^:]\\$/
+ : /.\/$/;
+
exports.tmpdir = function() {
var path;
if (isWindows) {
@@ -34,7 +37,7 @@ exports.tmpdir = function() {
process.env.TEMP ||
'/tmp';
}
- if (/[\\\/]$/.test(path))
+ if (trailingSlashRe.test(path))
path = path.slice(0, -1);
return path;
};
diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js
index b5f39973a6..dd1a1ae339 100644
--- a/test/parallel/test-os.js
+++ b/test/parallel/test-os.js
@@ -15,6 +15,12 @@ if (process.platform === 'win32') {
assert.equal(os.tmpdir(), expected);
process.env.TEMP = '\\temp\\';
assert.equal(os.tmpdir(), '\\temp');
+ process.env.TEMP = '\\tmpdir/';
+ assert.equal(os.tmpdir(), '\\tmpdir/');
+ process.env.TEMP = '\\';
+ assert.equal(os.tmpdir(), '\\');
+ process.env.TEMP = 'C:\\';
+ assert.equal(os.tmpdir(), 'C:\\');
} else {
assert.equal(os.tmpdir(), '/tmpdir');
process.env.TMPDIR = '';
@@ -25,6 +31,10 @@ if (process.platform === 'win32') {
assert.equal(os.tmpdir(), '/tmp');
process.env.TMPDIR = '/tmpdir/';
assert.equal(os.tmpdir(), '/tmpdir');
+ process.env.TMPDIR = '/tmpdir\\';
+ assert.equal(os.tmpdir(), '/tmpdir\\');
+ process.env.TMPDIR = '/';
+ assert.equal(os.tmpdir(), '/');
}
var endianness = os.endianness();