Skip to content

Commit 95fb0cc

Browse files
committed
CommandLineOptions: allow open-ended quotes in @-files.
We do not enforce an ending quote in @-files and simply close the string on end-fo-file. This might be nicer for the user and does not harm.
1 parent c6fab2f commit 95fb0cc

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

core/src/main/java/com/google/googlejavaformat/java/CommandLineOptionsParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ final class CommandLineOptionsParser {
4545
* For simplicity, we do not handle escaped quotes.
4646
*/
4747
private static final Pattern ARG_MATCHER = Pattern.compile(
48-
"\"([^\"]*)\"" + // group 1: string in double quotes, with whitespace allowed
48+
"\"([^\"]*)(?:\"|$)" + // group 1: string in double quotes (or until EOF), with whitespace allowed
4949
"|" + // OR
50-
"'([^']*)'" + // group 2: string in single quotes, with whitespace allowed
50+
"'([^']*)(?:'|$)" + // group 2: string in single quotes (or until EOF), with whitespace allowed
5151
"|" + // OR
5252
"([^\\s\"']+)" // group 3: unquoted string, without whitespace and without any quotes
5353
);

core/src/test/java/com/google/googlejavaformat/java/CommandLineOptionsParserTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ public void paramsFileWithQuotesAndWhitespaces() throws IOException {
226226

227227
String[] args = {"--dry-run", "@" + exit, "L +w", "@" + outer, "Q +w"};
228228

229-
Files.write(exit, "--set-exit-if-changed".getBytes(UTF_8));
229+
Files.write(exit, "--set-exit-if-changed 'K +w".getBytes(UTF_8));
230230
Files.write(outer, ("\"'M' +w\"\n\"@" + nested.toAbsolutePath() + "\"\n'\"P\" +w'").getBytes(UTF_8));
231-
Files.write(nested, "\"ℕ +w\"\n\n \n\"@@O +w\"\n".getBytes(UTF_8));
231+
Files.write(nested, "\"ℕ +w\"\n\n \n\"@@O +w\n".getBytes(UTF_8));
232232

233233
CommandLineOptions options = CommandLineOptionsParser.parse(Arrays.asList(args));
234-
assertThat(options.files()).containsExactly("L +w", "'M' +w", "ℕ +w", "@O +w", "\"P\" +w", "Q +w");
234+
assertThat(options.files()).containsExactly("K +w", "L +w", "'M' +w", "ℕ +w", "@O +w", "\"P\" +w", "Q +w");
235235
}
236236

237237
@Test

0 commit comments

Comments
 (0)