Skip to content

Commit b210587

Browse files
committed
Have to capture for backreference
1 parent 6212c3e commit b210587

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

qa/evil-tests/src/test/java/org/elasticsearch/monitor/os/EvilOsProbeTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public void testOsPrettyName() throws IOException {
3939
final List<String> lines = Files.readAllLines(PathUtils.get("/etc/os-release"));
4040
for (final String line : lines) {
4141
if (line != null && line.startsWith("PRETTY_NAME=")) {
42-
final Matcher matcher = Pattern.compile("PRETTY_NAME=(?:\"?|'?)?([^\"']+)\\1").matcher(line.trim());
42+
final Matcher matcher = Pattern.compile("PRETTY_NAME=(\"?|'?)?([^\"']+)\\1").matcher(line.trim());
4343
assert matcher.matches() : line;
44-
assert matcher.groupCount() == 1 : line;
45-
final String prettyName = matcher.group(1);
44+
assert matcher.groupCount() == 2 : line;
45+
final String prettyName = matcher.group(2);
4646
assertThat(osInfo.getPrettyName(), equalTo(prettyName));
4747
return;
4848
}

server/src/main/java/org/elasticsearch/monitor/os/OsProbe.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,10 @@ private String getPrettyName() throws IOException {
551551
if (maybePrettyNameLine.isPresent()) {
552552
// we trim since some OS contain trailing space, for example, Oracle Linux Server 6.9 has a trailing space after the quote
553553
final String trimmedPrettyNameLine = maybePrettyNameLine.get().trim();
554-
final Matcher matcher = Pattern.compile("PRETTY_NAME=(?:\"?|'?)?([^\"']+)\\1").matcher(trimmedPrettyNameLine);
554+
final Matcher matcher = Pattern.compile("PRETTY_NAME=(\"?|'?)?([^\"']+)\\1").matcher(trimmedPrettyNameLine);
555555
assert matcher.matches() : trimmedPrettyNameLine;
556-
assert matcher.groupCount() == 1 : trimmedPrettyNameLine;
557-
return matcher.group(1);
556+
assert matcher.groupCount() == 2 : trimmedPrettyNameLine;
557+
return matcher.group(2);
558558
} else {
559559
return Constants.OS_NAME;
560560
}

0 commit comments

Comments
 (0)