Skip to content

Commit

Permalink
os: remove trailing slash from os.tmpdir()
Browse files Browse the repository at this point in the history
This commit makes `os.tmpdir()` behave consistently on all platforms. It
changes `os.tmpdir()` to always return a path without trailing slash.

Semver: major
Fixes: #715
PR-URL: #747
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
tellnes committed Mar 21, 2015
1 parent bc1fe3a commit bb97b70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ exports.platform = function() {
};

exports.tmpdir = function() {
var path;
if (isWindows) {
return process.env.TEMP ||
path = process.env.TEMP ||
process.env.TMP ||
(process.env.SystemRoot || process.env.windir) + '\\temp';
} else {
return process.env.TMPDIR ||
path = process.env.TMPDIR ||
process.env.TMP ||
process.env.TEMP ||
'/tmp';
}
if (/[\\\/]$/.test(path))
path = path.slice(0, -1);
return path;
};

exports.tmpDir = exports.tmpdir;
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (process.platform === 'win32') {
process.env.TMP = '';
var expected = (process.env.SystemRoot || process.env.windir) + '\\temp';
assert.equal(os.tmpdir(), expected);
process.env.TEMP = '\\temp\\';
assert.equal(os.tmpdir(), '\\temp');
} else {
assert.equal(os.tmpdir(), '/tmpdir');
process.env.TMPDIR = '';
Expand All @@ -21,6 +23,8 @@ if (process.platform === 'win32') {
assert.equal(os.tmpdir(), '/temp');
process.env.TEMP = '';
assert.equal(os.tmpdir(), '/tmp');
process.env.TMPDIR = '/tmpdir/';
assert.equal(os.tmpdir(), '/tmpdir');
}

var endianness = os.endianness();
Expand Down

0 comments on commit bb97b70

Please sign in to comment.