Recover bug of ScriptPW.Password

This commit is contained in:
anseki 2015-03-05 17:39:46 +09:00
parent 7a37871966
commit a6039bcf36
5 changed files with 16 additions and 7 deletions

View file

@ -3,7 +3,7 @@ setlocal
setlocal ENABLEDELAYEDEXPANSION setlocal ENABLEDELAYEDEXPANSION
if "%1"=="noechoback" ( if "%1"=="noechoback" (
call :exprog call :read_s
if ERRORLEVEL 1 exit /b 1 if ERRORLEVEL 1 exit /b 1
) else ( ) else (
set /p INPUT=<CON >CON set /p INPUT=<CON >CON
@ -13,7 +13,8 @@ set /p ="'%INPUT%'"<NUL
endlocal endlocal
exit /b 0 exit /b 0
:exprog :: Silent Read
:read_s
:: where /q powershell :: where /q powershell
:: Win <Vista and <Server2008 don't have `where`. :: Win <Vista and <Server2008 don't have `where`.

View file

@ -4,7 +4,13 @@ var oExec;
// exit-code is not returned even if an error is thrown. // exit-code is not returned even if an error is thrown.
try { try {
WScript.StdOut.Write(WScript.CreateObject('ScriptPW.Password').GetPassword()); WScript.StdOut.Write(WScript.CreateObject('ScriptPW.Password').GetPassword()
// Bug? Illegal data may be returned when user types before initializing.
.replace(/[\u4000-\u40FF]/g, function(chr) {
var charCode = chr.charCodeAt(0);
return charCode >= 0x4020 && charCode <= 0x407F ?
String.fromCharCode(charCode - 0x4000) : '';
}));
} catch (e) { } catch (e) {
WScript.StdErr.Write(e.description); WScript.StdErr.Write(e.description);
WScript.Quit(1); WScript.Quit(1);

View file

@ -1,4 +1,5 @@
silent_read() { # Silent Read
read_s() {
stty --file=/dev/tty -echo echonl 2>/dev/null || \ stty --file=/dev/tty -echo echonl 2>/dev/null || \
stty -F /dev/tty -echo echonl 2>/dev/null || \ stty -F /dev/tty -echo echonl 2>/dev/null || \
stty -f /dev/tty -echo echonl || exit 1 stty -f /dev/tty -echo echonl || exit 1
@ -11,9 +12,9 @@ silent_read() {
if [ "$1" = "noechoback" ]; then if [ "$1" = "noechoback" ]; then
# Try `-s` option. *ksh have it that not `--silent`. Therefore, don't try it. # Try `-s` option. *ksh have it that not `--silent`. Therefore, don't try it.
if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then
IFS= read -rs INPUT </dev/tty 2>/dev/null && printf '\n' >/dev/tty || silent_read IFS= read -rs INPUT </dev/tty 2>/dev/null && printf '\n' >/dev/tty || read_s
else else
silent_read read_s
fi fi
else else
IFS= read -r INPUT </dev/tty || exit 1 IFS= read -r INPUT </dev/tty || exit 1

View file

@ -168,6 +168,7 @@ function _execSyncByFile(args, execOptions) {
' & (echo 1)>%Q%' + pathDone + '%Q%']; ' & (echo 1)>%Q%' + pathDone + '%Q%'];
} else { } else {
cmdArgs = ['-c', cmdArgs = ['-c',
// Use `()`, not `{}` for `-c` (text param)
'(' + SHELL_PATH + ' "' + SHELL_CMD + '" ' + args.join(' ') + '(' + SHELL_PATH + ' "' + SHELL_CMD + '" ' + args.join(' ') +
'; echo $?>"' + pathStatus + '") 2>"' + pathStderr + '"' + '; echo $?>"' + pathStatus + '") 2>"' + pathStderr + '"' +
' |"' + process.execPath + '" "' + __dirname + '/encrypt.js"' + ' |"' + process.execPath + '" "' + __dirname + '/encrypt.js"' +

View file

@ -1,6 +1,6 @@
{ {
"name": "readline-sync", "name": "readline-sync",
"version": "0.7.4", "version": "0.7.5",
"title": "readlineSync", "title": "readlineSync",
"description": "Synchronous Readline", "description": "Synchronous Readline",
"keywords": [ "keywords": [