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.tsjoined the java command, includingJAVA_OPTS, into a single string and spawned it withshell: true, so shell metacharacters inJAVA_OPTSchanged what was executed. A value like-Dhttp.nonProxyHosts=127.*|localhost|*.localwas read as a shell pipe and the CLI failed withError: 'localhost' is not recognized as an internal or external command. Thehelp/completiondiscovery probed at startup goes through the same code, so every CLI invocation crashed before a command even ran.What changed
cmd()now returns an argv array instead of a shell string:['java', ...splitArgs(JAVA_OPTS), '-jar', cliPath].JAVA_OPTSis split by a small tokenizer that respects quotes and backslash escapes, so a pipe in it reaches java as one argument.passThrough()and thehelp/completiondiscovery spawn with an args array andshell: false.version-manager.service.tsstill spawnsdocker pull/docker rmivia a shell string, as there is no user-controlled input there.Tests
JAVA_OPTS='-Dhttp.nonProxyHosts=127.*|localhost' openapi-generator-cli helpfailed before the change and prints the usage with exit code 0 after it (checked against the built CLI).pass-through.service.spec.tsmocksspawnand asserts the exact argv arrays, including an unquoted pipe and quotedJAVA_OPTS.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.