@@ -115,6 +115,39 @@ child.exec(...common.escapePOSIXShell`"${process.execPath}" -p "\\-42"`, common.
115115 assert . strictEqual ( stderr , '' ) ;
116116} ) ) ;
117117
118+ // Unary-negative eval expressions should not be rejected as missing arguments.
119+ child . exec ( ...common . escapePOSIXShell `"${ process . execPath } " -pe -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 } " -pe -0` , common . mustSucceed ( ( stdout , stderr ) => {
126+ assert . strictEqual ( stdout , '-0\n' ) ;
127+ assert . strictEqual ( stderr , '' ) ;
128+ } ) ) ;
129+
130+ // Expressions like -NaN should be treated as eval input, not options.
131+ child . exec ( ...common . escapePOSIXShell `"${ process . execPath } " -pe -NaN` , common . mustSucceed ( ( stdout , stderr ) => {
132+ assert . strictEqual ( stdout , 'NaN\n' ) ;
133+ assert . strictEqual ( stderr , '' ) ;
134+ } ) ) ;
135+
136+ // A bare '-' should be passed to eval and fail with a syntax error.
137+ child . exec ( ...common . escapePOSIXShell `"${ process . execPath } " -pe -` , common . mustCall ( ( err , stdout , stderr ) => {
138+ assert . notStrictEqual ( err . code , 9 ) ;
139+ assert . strictEqual ( stdout , '' ) ;
140+ assert . match ( stderr , / S y n t a x E r r o r / ) ;
141+ } ) ) ;
142+
143+ // Nearby-path safety: option-looking values should still be rejected.
144+ child . exec ( ...common . escapePOSIXShell `"${ process . execPath } " -e -p` , common . mustCall ( ( err , stdout , stderr ) => {
145+ assert . strictEqual ( err . code , 9 ) ;
146+ assert . strictEqual ( stdout , '' ) ;
147+ assert . strictEqual ( stderr . trim ( ) ,
148+ `${ process . execPath } : -e requires an argument` ) ;
149+ } ) ) ;
150+
118151// Long output should not be truncated.
119152child . exec ( ...common . escapePOSIXShell `"${ process . execPath } " -p "'1'.repeat(1e5)"` , common . mustSucceed ( ( stdout , stderr ) => {
120153 assert . strictEqual ( stdout , `${ '1' . repeat ( 1e5 ) } \n` ) ;
0 commit comments