nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.66k stars 29.09k forks source link

process.env['TEMP'] incorrect on windows when username is bizarre and contains multiple apostrophes #37427

Closed nomagick closed 3 years ago

nomagick commented 3 years ago

What steps will reproduce the bug?

process.env['TEMP'] === 'C:\Users\YUAN'Q~1\AppData\Local\Temp';

Which is INCORRECT.

It should be C:\Users\yuan'qian'wen\AppData\Local\Temp

How often does it reproduce? Is there a required condition?

The windows user name be yuan'qian'wen;

User name bizarre'a'b'c does not reproduce this issue;

What is the expected behavior?

process.env['TEMP'] === C:\Users\yuan'qian'wen\AppData\Local\Temp;

What do you see instead?

Additional information

C:\Users\yuan'qian'wen>node
Welcome to Node.js v15.7.0.
Type ".help" for more information.
> process.env
{
  ALLUSERSPROFILE: 'C:\\ProgramData',
  APPDATA: "C:\\Users\\yuan'qian'wen\\AppData\\Roaming",
  CommonProgramFiles: 'C:\\Program Files\\Common Files',
  'CommonProgramFiles(x86)': 'C:\\Program Files (x86)\\Common Files',
  CommonProgramW6432: 'C:\\Program Files\\Common Files',
  COMPUTERNAME: 'DESKTOP-29O4BQV',
  ComSpec: 'C:\\WINDOWS\\system32\\cmd.exe',
  DriverData: 'C:\\Windows\\System32\\Drivers\\DriverData',
  FPS_BROWSER_APP_PROFILE_STRING: 'Internet Explorer',
  FPS_BROWSER_USER_PROFILE_STRING: 'Default',
  HOMEDRIVE: 'C:',
  HOMEPATH: "\\Users\\yuan'qian'wen",
  LOCALAPPDATA: "C:\\Users\\yuan'qian'wen\\AppData\\Local",
  LOGONSERVER: '\\\\DESKTOP-29O4BQV',
  NUMBER_OF_PROCESSORS: '4',
  OS: 'Windows_NT',
  Path: "C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\nodejs;C:\\Program Files\\Git\\cmd;C:\\Program Files\\nodejs\\;C:\\Users\\yuan'qian'wen\\AppData\\Local\\Microsoft\\WindowsApps;",
  PATHEXT: '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
  PROCESSOR_ARCHITECTURE: 'AMD64',
  PROCESSOR_IDENTIFIER: 'Intel64 Family 6 Model 158 Stepping 9, GenuineIntel',
  PROCESSOR_LEVEL: '6',
  PROCESSOR_REVISION: '9e09',
  ProgramData: 'C:\\ProgramData',
  ProgramFiles: 'C:\\Program Files',
  'ProgramFiles(x86)': 'C:\\Program Files (x86)',
  ProgramW6432: 'C:\\Program Files',
  PROMPT: '$P$G',
  PSModulePath: 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules;C:\\Program Files (x86)\\VMware\\Infrastructure\\PowerCLI\\Modules',
  PUBLIC: 'C:\\Users\\Public',
  SESSIONNAME: 'Console',
  SystemDrive: 'C:',
  SystemRoot: 'C:\\WINDOWS',
  TEMP: "C:\\Users\\YUAN'Q~1\\AppData\\Local\\Temp",
  TMP: "C:\\Users\\YUAN'Q~1\\AppData\\Local\\Temp",
  USERDOMAIN: 'DESKTOP-29O4BQV',
  USERDOMAIN_ROAMINGPROFILE: 'DESKTOP-29O4BQV',
  USERNAME: "yuan'qian'wen",
  USERPROFILE: "C:\\Users\\yuan'qian'wen",
  windir: 'C:\\WINDOWS'
}
>    
nomagick commented 3 years ago

This issue was encountered on an Electron App (electron 11.2.1) on Windows 10.

Creating a user with the same name yuan'qian'wen would reproduce this issue.

Same thing happends to both Electron and Node.

aduh95 commented 3 years ago

I might be wrong, but I think you env variable is actually C:\Users\YUAN'Q~1\AppData\Local\Temp, and Node.js is returning the "correct" value. Try echo %TEMP% in CMD, I think it should display the same string.

nomagick commented 3 years ago

I might be wrong, but I think you env variable is actually C:\Users\YUAN'Q~1\AppData\Local\Temp, and Node.js is returning the "correct" value. Try echo %TEMP% in CMD, I think it should display the same string.

echo %TEMP% indeed returns C:\Users\YUAN'Q~1\AppData\Local\Temp.

Not a node.js issue then, sorry...