Skip to content

Commit 4c2d3f2

Browse files
authored
Merge pull request #278 from mbargiel/feature/fix-268-revert-sanitize-name
fix #268: Revert "fix #246: remove any double quotes or single quotes…
2 parents 7e96f4d + a831713 commit 4c2d3f2

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

lib/tmp.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ function _assertAndSanitizeOptions(options) {
535535
options.template = _isBlank(options.template) ? undefined : path.relative(options.dir, options.template);
536536

537537
// for completeness' sake only, also keep (multiple) blanks if the user, purportedly sane, requests us to
538-
options.name = _isUndefined(options.name) ? undefined : _sanitizeName(options.name);
538+
options.name = _isUndefined(options.name) ? undefined : options.name;
539539
options.prefix = _isUndefined(options.prefix) ? '' : options.prefix;
540540
options.postfix = _isUndefined(options.postfix) ? '' : options.postfix;
541541
}
@@ -552,28 +552,13 @@ function _assertAndSanitizeOptions(options) {
552552
* @private
553553
*/
554554
function _resolvePath(name, tmpDir) {
555-
const sanitizedName = _sanitizeName(name);
556-
if (sanitizedName.startsWith(tmpDir)) {
557-
return path.resolve(sanitizedName);
555+
if (name.startsWith(tmpDir)) {
556+
return path.resolve(name);
558557
} else {
559-
return path.resolve(path.join(tmpDir, sanitizedName));
558+
return path.resolve(path.join(tmpDir, name));
560559
}
561560
}
562561

563-
/**
564-
* Sanitize the specified path name by removing all quote characters.
565-
*
566-
* @param name
567-
* @returns {string}
568-
* @private
569-
*/
570-
function _sanitizeName(name) {
571-
if (_isBlank(name)) {
572-
return name;
573-
}
574-
return name.replace(/["']/g, '');
575-
}
576-
577562
/**
578563
* Asserts whether specified name is relative to the specified tmpDir.
579564
*
@@ -663,7 +648,7 @@ function setGracefulCleanup() {
663648
* @returns {string} the currently configured tmp dir
664649
*/
665650
function _getTmpDir(options) {
666-
return path.resolve(_sanitizeName(options && options.tmpdir || os.tmpdir()));
651+
return path.resolve(options && options.tmpdir || os.tmpdir());
667652
}
668653

669654
// Install process exit listener

test/name-sync-test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const
55
assert = require('assert'),
66
os = require('os'),
7+
path = require('path'),
78
inbandStandardTests = require('./name-inband-standard'),
89
tmp = require('../lib/tmp');
910

@@ -53,30 +54,30 @@ describe('tmp', function () {
5354
}
5455
});
5556
});
56-
describe('on issue #246', function () {
57+
describe('on issue #268', function () {
5758
const origfn = os.tmpdir;
58-
it('must produce correct name on os.tmpdir() returning path that includes double quotes', function () {
59+
it(`should not alter ${isWindows ? 'invalid' : 'valid'} path on os.tmpdir() returning path that includes double quotes`, function () {
5960
const tmpdir = isWindows ? '"C:\\Temp With Spaces"' : '"/tmp with spaces"';
6061
os.tmpdir = function () {
6162
return tmpdir;
6263
};
6364
const name = tmp.tmpNameSync();
65+
const index = name.indexOf(path.sep + tmpdir + path.sep);
6466
try {
65-
assert.ok(name.indexOf('"') === -1);
66-
assert.ok(name.startsWith(tmpdir.replace(/["']/g, '')));
67+
assert.ok(index > 0, `${tmpdir} should have been a subdirectory name in ${name}`);
6768
} finally {
6869
os.tmpdir = origfn;
6970
}
7071
});
71-
it('must produce correct name on os.tmpdir() returning path that includes single quotes', function () {
72+
it('should not alter valid path on os.tmpdir() returning path that includes single quotes', function () {
7273
const tmpdir = isWindows ? '\'C:\\Temp With Spaces\'' : '\'/tmp with spaces\'';
7374
os.tmpdir = function () {
7475
return tmpdir;
7576
};
7677
const name = tmp.tmpNameSync();
78+
const index = name.indexOf(path.sep + tmpdir + path.sep);
7779
try {
78-
assert.ok(name.indexOf('\'') === -1);
79-
assert.ok(name.startsWith(tmpdir.replace(/["']/g, '')));
80+
assert.ok(index > 0, `${tmpdir} should have been a subdirectory name in ${name}`);
8081
} finally {
8182
os.tmpdir = origfn;
8283
}

test/name-test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const
55
assert = require('assert'),
66
os = require('os'),
7+
path = require('path'),
78
inbandStandardTests = require('./name-inband-standard'),
89
tmp = require('../lib/tmp');
910

@@ -63,15 +64,15 @@ describe('tmp', function () {
6364
});
6465
});
6566
});
66-
describe('on issue #246', function () {
67+
describe('on issue #268', function () {
6768
const origfn = os.tmpdir;
68-
it('must produce correct name on os.tmpdir() returning path that includes double quotes', function (done) {
69+
it(`should not alter ${isWindows ? 'invalid' : 'valid'} path on os.tmpdir() returning path that includes double quotes`, function (done) {
6970
const tmpdir = isWindows ? '"C:\\Temp With Spaces"' : '"/tmp with spaces"';
7071
os.tmpdir = function () { return tmpdir; };
7172
tmp.tmpName(function (err, name) {
73+
const index = name.indexOf(path.sep + tmpdir + path.sep);
7274
try {
73-
assert.ok(name.indexOf('"') === -1);
74-
assert.ok(name.startsWith(tmpdir.replace(/["']/g, '')));
75+
assert.ok(index > 0, `${tmpdir} should have been a subdirectory name in ${name}`);
7576
} catch (err) {
7677
return done(err);
7778
} finally {
@@ -80,13 +81,13 @@ describe('tmp', function () {
8081
done();
8182
});
8283
});
83-
it('must produce correct name on os.tmpdir() returning path that includes single quotes', function (done) {
84+
it('should not alter valid path on os.tmpdir() returning path that includes single quotes', function (done) {
8485
const tmpdir = isWindows ? '\'C:\\Temp With Spaces\'' : '\'/tmp with spaces\'';
8586
os.tmpdir = function () { return tmpdir; };
8687
tmp.tmpName(function (err, name) {
88+
const index = name.indexOf(path.sep + tmpdir + path.sep);
8789
try {
88-
assert.ok(name.indexOf('\'') === -1);
89-
assert.ok(name.startsWith(tmpdir.replace(/["']/g, '')));
90+
assert.ok(index > 0, `${tmpdir} should have been a subdirectory name in ${name}`);
9091
} catch (err) {
9192
return done(err);
9293
} finally {

0 commit comments

Comments
 (0)