Skip to content

Commit

Permalink
Windows shells can preserve quotes on an argument. Remove the extra q…
Browse files Browse the repository at this point in the history
…uotes.

Closes #3081

Closes #3083.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=214853099
  • Loading branch information
ChadKillingsworth authored and brad4d committed Sep 28, 2018
1 parent ecd8a5a commit 00565cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/com/google/javascript/jscomp/CommandLineRunner.java
Expand Up @@ -1340,8 +1340,16 @@ private MultiFlagSetter(
}

@Override public void addValue(String value) throws CmdLineException {
proxy.addValue(value);
entries.add(new FlagEntry<>(flag, value));
// On windows, some quoted values seem to preserve the quotes as part of the value.
String normalizedValue = value;
if (value != null
&& value.length() > 0
&& (value.substring(0, 1).equals("'") || value.substring(0, 1).equals("\""))
&& value.substring(value.length() - 1).equals(value.substring(0, 1))) {
normalizedValue = value.substring(1, value.length() - 1);
}
proxy.addValue(normalizedValue);
entries.add(new FlagEntry<>(flag, normalizedValue));
}

@Override public FieldSetter asFieldSetter() {
Expand Down
8 changes: 8 additions & 0 deletions test/com/google/javascript/jscomp/CommandLineRunnerTest.java
Expand Up @@ -2431,6 +2431,14 @@ public void testEscapeDollarInTemplateLiteralEs5Output() {
"var Foo, x = '\\${Foo}'+Foo;");
}

/** windows shells can add extra quotes to an argument */
@Test
public void testWarningGuardQuotedValue() {
args.add("--jscomp_error='\"*\"'");
args.add("--jscomp_warning=\"'*'\"");
args.add("--jscomp_off='\"*\"'");
testSame("alert('hello world')");
}

/* Helper functions */

Expand Down

0 comments on commit 00565cb

Please sign in to comment.