summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoogler <noreply@google.com>2017-01-25 22:16:18 +0000
committerColin Cross <ccross@android.com>2017-02-16 22:40:04 -0800
commitcbc8311503e7d22bf16e779c9aa5f13e9c538cfb (patch)
tree1fe54fa6d4cfbef715d5548441efd2e0e78eaafb
parentce9551c24ef77db7c91b1b5478e2d13b7bfc39c1 (diff)
downloaddesugar-cbc8311503e7d22bf16e779c9aa5f13e9c538cfb.tar.gz
Fix the OptionsParser to deal with CRLF line endings.
Fixes https://github.com/bazelbuild/bazel/issues/2416 -- PiperOrigin-RevId: 145595491 MOS_MIGRATED_REVID=145595491 GitOrigin-RevId: 4d0f864fb17b2f5ada4280e5758f924628f990c2 Change-Id: I49ac0ea2cdcbdbb7bfba081fcc8b85f5763c94f2
-rw-r--r--java/com/google/devtools/common/options/ParamsFilePreProcessor.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/java/com/google/devtools/common/options/ParamsFilePreProcessor.java b/java/com/google/devtools/common/options/ParamsFilePreProcessor.java
index 02fe877..bd1c5a9 100644
--- a/java/com/google/devtools/common/options/ParamsFilePreProcessor.java
+++ b/java/com/google/devtools/common/options/ParamsFilePreProcessor.java
@@ -74,7 +74,7 @@ public class ParamsFilePreProcessor implements ArgsPreProcessor {
arg.append(next);
}
}
- // If there is still an arg in the buffer, add it.
+ // If there is an arg in the buffer, add it.
if (arg.length() > 0) {
newArgs.add(arg.toString());
}
@@ -111,10 +111,14 @@ public class ParamsFilePreProcessor implements ArgsPreProcessor {
}
public boolean hasNext() throws IOException {
+ return peek() != -1;
+ }
+
+ private int peek() throws IOException {
reader.mark(1);
int next = reader.read();
reader.reset();
- return next != -1;
+ return next;
}
public boolean isInQuote() {
@@ -141,6 +145,11 @@ public class ParamsFilePreProcessor implements ArgsPreProcessor {
throw new NoSuchElementException();
}
char current = (char) reader.read();
+
+ // check for \r\n line endings. If found, drop the \r for normalized parsing.
+ if (current == '\r' && peek() == '\n') {
+ current = (char) reader.read();
+ }
// check to see if the current position is escaped
if (lastChar == '\\') {