Skip to content

Read quoted arguments from parameter files, and refuse a file that includes itself - #49

Merged
abashev merged 1 commit into
mainfrom
argfile-quotes
Sep 23, 2026
Merged

abashev merged 1 commit into
mainfrom
argfile-quotes

Conversation

@abashev

@abashev abashev commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

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:

  • an argument in an @argfile may 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;
  • an unclosed quote runs to the end of the file; escaped quotes are not handled, as upstream;
  • a parameter file that includes itself is reported as "parameter file was included recursively" instead of overflowing the stack.

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_MATCHER finds 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. paramFilesStack holds 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 paramsFileWithQuotesAndWhitespaces are edge cases, with +w marking an argument that contains whitespace: "'M' +w" keeps its single quotes, '"P" +w' keeps its double quotes, 'K +w is an unclosed quote at the end of a file, and "@@O +w is an escaped @ inside an unclosed quote.

Checked

…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
abashev enabled auto-merge September 23, 2026 08:53
@abashev
abashev disabled auto-merge September 23, 2026 14:18
@abashev
abashev merged commit 43f5d3d into main Sep 23, 2026
14 checks passed
@abashev
abashev deleted the argfile-quotes branch September 23, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants