Skip to content

Commit

Permalink
CommandLineOptions: allow open-ended quotes in @-files.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kfriedberger committed Apr 7, 2023
1 parent c6fab2f commit 95fb0cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95fb0cc

Please sign in to comment.