1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-27 12:46:22 +01:00

Tolerate missing terminating newlines in Java release files

Had a report out in the wild of a release file that doesn't end in a
terminating newline, which was causing the parser to blow up.
This commit relaxes the parsing to tolerate EOFs while parsing values.
This commit is contained in:
Henry Le Grys 2021-09-27 21:21:46 +01:00
parent 1c663e1c04
commit 9bd7df4d3c

View File

@ -85,23 +85,28 @@ public class EnvironmentParser {
private String parseValue() throws IOException {
StringBuilder buffer = new StringBuilder();
while (true) {
char c = read();
try {
while (true) {
char c = read();
switch (c) {
case '\r':
case '\n':
return buffer.toString();
case '"':
buffer.append(parseQuotedPhrase());
break;
case '\\':
char next = read();
buffer.append(next);
break;
default:
buffer.append(c);
switch (c) {
case '\r':
case '\n':
return buffer.toString();
case '"':
buffer.append(parseQuotedPhrase());
break;
case '\\':
char next = read();
buffer.append(next);
break;
default:
buffer.append(c);
}
}
} catch (EOFException e) {
// No terminating newline. bad!
return buffer.toString();
}
}