diff --git a/core/src/main/java/com/google/googlejavaformat/java/CommandLineOptionsParser.java b/core/src/main/java/com/google/googlejavaformat/java/CommandLineOptionsParser.java index 5faedd8ad..5ecee8649 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/CommandLineOptionsParser.java +++ b/core/src/main/java/com/google/googlejavaformat/java/CommandLineOptionsParser.java @@ -45,9 +45,9 @@ final class CommandLineOptionsParser { * For simplicity, we do not handle escaped quotes. */ private static final Pattern ARG_MATCHER = Pattern.compile( - "\"([^\"]*)\"" + // group 1: string in double quotes, with whitespace allowed + "\"([^\"]*)(?:\"|$)" + // group 1: string in double quotes (or until EOF), with whitespace allowed "|" + // OR - "'([^']*)'" + // group 2: string in single quotes, with whitespace allowed + "'([^']*)(?:'|$)" + // group 2: string in single quotes (or until EOF), with whitespace allowed "|" + // OR "([^\\s\"']+)" // group 3: unquoted string, without whitespace and without any quotes ); diff --git a/core/src/test/java/com/google/googlejavaformat/java/CommandLineOptionsParserTest.java b/core/src/test/java/com/google/googlejavaformat/java/CommandLineOptionsParserTest.java index 1d241393c..85165f4ca 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/CommandLineOptionsParserTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/CommandLineOptionsParserTest.java @@ -226,12 +226,12 @@ public void paramsFileWithQuotesAndWhitespaces() throws IOException { String[] args = {"--dry-run", "@" + exit, "L +w", "@" + outer, "Q +w"}; - Files.write(exit, "--set-exit-if-changed".getBytes(UTF_8)); + Files.write(exit, "--set-exit-if-changed 'K +w".getBytes(UTF_8)); Files.write(outer, ("\"'M' +w\"\n\"@" + nested.toAbsolutePath() + "\"\n'\"P\" +w'").getBytes(UTF_8)); - Files.write(nested, "\"ℕ +w\"\n\n \n\"@@O +w\"\n".getBytes(UTF_8)); + Files.write(nested, "\"ℕ +w\"\n\n \n\"@@O +w\n".getBytes(UTF_8)); CommandLineOptions options = CommandLineOptionsParser.parse(Arrays.asList(args)); - assertThat(options.files()).containsExactly("L +w", "'M' +w", "ℕ +w", "@O +w", "\"P\" +w", "Q +w"); + assertThat(options.files()).containsExactly("K +w", "L +w", "'M' +w", "ℕ +w", "@O +w", "\"P\" +w", "Q +w"); } @Test