raszi / node-tmp

Temporary file and directory creator for node.js
MIT License
736 stars 92 forks source link

tmpNameSync: Bad result if the TMP/TEMP env. variables are enclosed in quotes #246

Closed haneefdm closed 4 years ago

haneefdm commented 4 years ago

Operating System

NodeJS Version

Tmp Version

TBD:0.1.0

Expected Behavior

TBD: What have you expected tmp to do?

Create proper tmp-name without quotes

Experienced Behavior

TBD: What did actually happen?

Created path names with embedded quotes if the env. vars TMP and TEMP has spaces in it. I have a space in my user name and we have to use our own TMP directories rather than using the system ones. To reproduce the problem in a shell/cmd set the TMP/TEMP variables to any path with spaces in it

set TMP="C:\users\xxx\T M P" set TEMP="C:\users\xxx\T M P" node test.js

The above commands creates the following output. Yes, I can filter the path-name but it was unexpected

Created temporary filename:  "C:\Users\hdm\T M P"\tmp-4832vNUYEwQFRehF

And my test.js looks like

var tmp = require('tmp');
var options = {};
var tmpname = tmp.tmpNameSync(options);
console.log('Created temporary filename: ', tmpname);
silkentrance commented 4 years ago

This also applies to the dir option, the template option and the name option.

silkentrance commented 4 years ago

The downside of this is that the user may no longer include a single single quote or a single double quote in the path. But this seems to be a rather fringe use case to me, so we will not support it any more.

haneefdm commented 4 years ago

Please, please don't make any changes; I was WRONG. Quotes are part of the string I suppose.

Microsoft Windows [Version 10.0.18362.535]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\hdm>set BLAH="a b c"

C:\Users\hdm>echo %BLAH%
"a b c"

C:\Users\hdm>set BLAH=a b c

C:\Users\hdm>echo %BLAH%
a b c

I am so so sorry to report this issue and wasted your time.

silkentrance commented 4 years ago

Way too late :smile:. This has already been merged and I think that it is ok handling this rather fringe case. The user might also be passing in a string for template or name or dir that might contain single quotes or double quotes.