Skip to content

Commit 17be1c2

Browse files
authored
Split on line feed when parsing transport files in the build (#135978) (#135985)
When parsing transport files that may contain comments we split on newline. On windows systems these files _might_ have the line feed replaced by CRLF. This commit adjusts the parsing to only split on line feed so that regardless of what the system line separator is we will split the lines as needed.
1 parent b869bff commit 17be1c2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionDefinition.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ public static TransportVersionDefinition fromString(Path file, String contents,
2222

2323
String idsLine = null;
2424
if (contents.isEmpty() == false) {
25-
String[] lines = contents.split(System.lineSeparator());
25+
// Regardless of whether windows newlines exist (they could be added by git), we split on line feed.
26+
// All we care about skipping lines with the comment character, so the remaining \r won't matter
27+
String[] lines = contents.split("\n");
2628
for (String line : lines) {
27-
line = line.replaceAll("\\s+", "");
29+
line = line.strip();
2830
if (line.startsWith("#") == false) {
2931
idsLine = line;
3032
break;

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionUpperBound.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ public static TransportVersionUpperBound fromString(Path file, String contents)
2424
String branch = filename.substring(slashIndex == -1 ? 0 : (slashIndex + 1), filename.length() - 4);
2525

2626
String idsLine = null;
27-
String[] lines = contents.split(System.lineSeparator());
27+
// Regardless of whether windows newlines exist (they could be added by git), we split on line feed.
28+
// All we care about skipping lines with the comment character, so the remaining \r won't matter
29+
String[] lines = contents.split("\n");
2830
for (String line : lines) {
29-
line = line.replaceAll("\\s+", "");
31+
line = line.strip();
3032
if (line.startsWith("#") == false) {
3133
idsLine = line;
3234
break;

0 commit comments

Comments
 (0)