Repository navigation
Conversation
JAVA_OPTS was interpolated into a single command string which was spawned with shell: true. Characters that are meaningful to a shell - most notably the pipe in -Dhttp.nonProxyHosts=127.*|localhost - were therefore interpreted by the shell instead of reaching the java process, breaking every command of the CLI (the command discovery via exec failed the same way). Joining the args into one string also triggered the Node.js DEP0190 deprecation warning. The command is now built as a proper argv array: JAVA_OPTS is split with a lightweight tokenizer that respects single/double quotes and backslash escapes, and java (or docker) is spawned with shell: false. This removes the whole class of shell-escaping problems. Fixes OpenAPITools#1213
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
splitArgs treated a backslash outside of quotes as an escape character the way a POSIX shell would, so a Windows path in JAVA_OPTS such as C:\certs\client.jks reached java as C:certsclient.jks. Unquoted backslashes are now kept verbatim; escaping is only interpreted inside double quotes, where it follows the typical shell rules.
…A_OPTS Within a double-quoted JAVA_OPTS segment a backslash closed nothing and a following quote always terminated the segment, so -Dfoo="a\"b" was passed to java as -Dfoo=a\b" with the trailing quote leaking out of the quotes. A backslash inside double quotes now escapes exactly the characters a typical shell lets it escape (quote, backslash, dollar, backtick), while single-quoted segments keep treating the backslash as a literal character.
The discovery of getCommands() was only exercised through a mock keyed
on the joined command line; the first two spawn calls were never
verified. The spec now asserts that help and completion are spawned on
the exact argv (java, jar path, sub command) with { shell: false }, and
the discovery beforeEach clears JAVA_OPTS so earlier tests cannot leak
options into the asserted argv.
The discovery run() accumulated stdout/stderr from Buffer chunks, so a multi-byte utf8 character split across two chunks was decoded twice and turned into replacement characters, corrupting non-ASCII help or error text. Both streams now set utf8 encoding before the data handlers are attached, and the spec asserts the encoding on the discovery streams.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1213.
pass-through.service.tsbuilt the java command by joining['java', process.env['JAVA_OPTS'], '-jar "..."', ...]into a single string and spawning it withshell: true. Any character that is meaningful to a shell therefore changed what was executed. The pipe in a legitimateJAVA_OPTSlikewas interpreted as a shell pipe, so the CLI failed with
This also affected the
exec()-based command discovery (help/completionare probed at startup), i.e. every CLI invocation crashed before a command even ran. Joining args into one string additionally triggered the Node.js deprecation warning DEP0190 (passing args to ashell: truespawn).What changed
cmd()now returns a proper argv array instead of a shell string:['java', ...splitArgs(JAVA_OPTS), '-jar', cliPath](and['docker', 'run', '--rm', '-v', cwd:/local, image]in docker mode).JAVA_OPTSis split by a lightweight tokenizer that respects single quotes, double quotes and backslash escapes, so-Dhttp.nonProxyHosts=127.*|localhost(quoted or unquoted) arrives at the java process as one verbatim argument.passThrough()and thehelp/completiondiscovery now spawn with an args array andshell: false;stdio: 'inherit'and the exit-code handling stay the same. Removing the shell eliminates the entire class of escaping problems (including DEP0190) instead of trying to quote for cmd.exe/POSIX at once.Note:
version-manager.service.tsstill spawnsdocker pull/docker rmivia a shell string — those commands contain no user-controlled input, so I left them untouched to keep this change focused.Reproduction / verification
The second case was verified against the built CLI (Node 24, Windows): it downloads the selected generator, runs the help/completion discovery via java and prints the usage text with exit code 0.
Tests
pass-through.service.spec.tsnow mocksspawn(returning anEventEmitterchild) for both the discovery calls and the passthrough spawn, and asserts the exact argv arrays.JAVA_OPTSwith an unquoted pipe is passed as a single argument, and quotedJAVA_OPTS(-Dhttp.nonProxyHosts="127.*|localhost|*.local",-Dsome.opt='a b') is split into separate arguments — both withshell: false.spawn(command, args, options)form, keeping the same scenarios (docker, plain,JAVA_OPTS, custom generator with/without the standard jar).npx nx test generator-cli: 255 tests passing;npx nx lint generator-cliclean.Summary by cubic
Fixes every CLI command crashing when
JAVA_OPTScontains shell-special characters. The java command was built by interpolatingJAVA_OPTSinto a single string and spawned withshell: true, so a legitimate value like-Dhttp.nonProxyHosts=127.*|localhostwas parsed as a pipe and failed startup; commands are now spawned as an argv array withshell: false.JAVA_OPTSis split by a tokenizer that respects quotes; unquoted backslashes are kept verbatim so Windows paths likeC:\certs\client.jkssurvive, while backslash escapes are interpreted only inside double quotes.Details
help/completiondiscovery now usesspawnwith an args array instead ofexec, and decodes output as utf8 so multi-byte characters split across chunks aren't rewritten as replacement characters.version-managerdocker pull/rm still uses shell strings since they contain no user-controlled input.Written for commit 5091168. Summary will update on new commits.