| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 475e5bd commit 0d62195
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -894,6 +894,9 @@ changes: | |||
| 894 | 894 | Evaluate the following argument as JavaScript. The modules which are | |
| 895 | 895 | predefined in the REPL can also be used in `script`. | |
| 896 | 896 | ||
| 897 | + If `script` starts with `-`, pass it using `=` (for example, | ||
| 898 | + `node --print --eval=-42`) so it is parsed as the value of `--eval`. | ||
| 899 | + | ||
| 897 | 900 | On Windows, using `cmd.exe` a single quote will not work correctly because it | |
| 898 | 901 | only recognizes double `"` for quoting. In Powershell or Git bash, both `'` | |
| 899 | 902 | and `"` are usable. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -115,6 +115,26 @@ child.exec(...common.escapePOSIXShell`"${process.execPath}" -p "\\-42"`, common. | |||
| 115 | 115 | assert.strictEqual(stderr, ''); | |
| 116 | 116 | })); | |
| 117 | 117 | ||
| 118 | + // Eval expressions that start with '-' can be passed with '='. | ||
| 119 | + child.exec(...common.escapePOSIXShell`"${process.execPath}" --print --eval=-42`, common.mustSucceed((stdout, stderr) => { | ||
| 120 | + assert.strictEqual(stdout, '-42\n'); | ||
| 121 | + assert.strictEqual(stderr, ''); | ||
| 122 | + })); | ||
| 123 | + | ||
| 124 | + // Edge case: negative zero should preserve its sign when printed. | ||
| 125 | + child.exec(...common.escapePOSIXShell`"${process.execPath}" --print --eval=-0`, common.mustSucceed((stdout, stderr) => { | ||
| 126 | + assert.strictEqual(stdout, '-0\n'); | ||
| 127 | + assert.strictEqual(stderr, ''); | ||
| 128 | + })); | ||
| 129 | + | ||
| 130 | + // Nearby-path safety: option-looking values should still be rejected with -e. | ||
| 131 | + child.exec(...common.escapePOSIXShell`"${process.execPath}" -e -p`, common.mustCall((err, stdout, stderr) => { | ||
| 132 | + assert.strictEqual(err.code, 9); | ||
| 133 | + assert.strictEqual(stdout, ''); | ||
| 134 | + assert.strictEqual(stderr.trim(), | ||
| 135 | + `${process.execPath}: -e requires an argument`); | ||
| 136 | + })); | ||
| 137 | + | ||
| 118 | 138 | // Long output should not be truncated. | |
| 119 | 139 | child.exec(...common.escapePOSIXShell`"${process.execPath}" -p "'1'.repeat(1e5)"`, common.mustSucceed((stdout, stderr) => { | |
| 120 | 140 | assert.strictEqual(stdout, `${'1'.repeat(1e5)}\n`); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments