Read quoted arguments from parameter files, and refuse a file that includes itself - #49
Merged
Merged
Conversation
…cludes itself CommandLineOptionsParser split an @argfile at every whitespace character and knew no quotes, so a path with a space in it became several arguments. Each was reported as "Skipping non-Java file", and the run still exited 0 (#40, from google/google-java-format#421). A parameter file that included itself recursed until the stack overflowed. This ports google/google-java-format#931 by Karlheinz Friedberger, its three commits squashed into one. An argument in a parameter file may be quoted with double or single quotes and then keeps its whitespace; an unclosed quote runs to the end of the file; and a file that is already being read is reported as "parameter file was included recursively". Escaped quotes are not handled, as upstream. The three CommandLineOptionsParserTest cases come from that PR.
abashev
enabled auto-merge
September 23, 2026 08:53
abashev
disabled auto-merge
September 23, 2026 14:18
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.
Part of #40, split out of #45. Upstream report: google/google-java-format#421.
From upstream, with the author kept
google/google-java-format#931 by Karlheinz Friedberger (open upstream), its three commits squashed into one:
@argfilemay be quoted with double or single quotes and then keeps its whitespace, so a path with a space in it is one path. Before, it became several arguments, each reported as "Skipping non-Java file", and the run still exited 0;The one change for argfiles that worked before: a path that contains a
'or"is now read as a quoted string.How it reads a file
ARG_MATCHERfinds one token at a time: a string in double quotes (group 1), a string in single quotes (group 2), or a run of characters without whitespace or quotes (group 3). The quotes are not part of the value.paramFilesStackholds the argfiles being read right now; a file already on it is an error, and a file included twice one after the other is still fine.The odd strings in
paramsFileWithQuotesAndWhitespacesare edge cases, with+wmarking an argument that contains whitespace:"'M' +w"keeps its single quotes,'"P" +w'keeps its double quotes,'K +wis an unclosed quote at the end of a file, and"@@O +wis an escaped@inside an unclosed quote.Checked
./gradlew :open-java-format:teston JDK 21: 1450 tests, all green.