From: Christian Tellnes Date: Fri, 6 Feb 2015 22:27:22 +0000 (+0100) Subject: os: remove trailing slash from os.tmpdir() X-Git-Tag: v2.0.0~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b57cc51d8d3f4ad279591ae8fa6584ee22773b97;p=platform%2Fupstream%2Fnodejs.git os: remove trailing slash from os.tmpdir() 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: https://github.com/iojs/io.js/issues/715 PR-URL: https://github.com/iojs/io.js/pull/747 Reviewed-By: Ben Noordhuis --- diff --git a/lib/os.js b/lib/os.js index 75a863e..cd4eb1c 100644 --- a/lib/os.js +++ b/lib/os.js @@ -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; diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index ae57353..b5f3997 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -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 = ''; @@ -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();