diff --git a/oshi-core/src/main/java/oshi/software/os/linux/LinuxOSVersionInfoEx.java b/oshi-core/src/main/java/oshi/software/os/linux/LinuxOSVersionInfoEx.java index 7f8b2085177..f3711eea372 100644 --- a/oshi-core/src/main/java/oshi/software/os/linux/LinuxOSVersionInfoEx.java +++ b/oshi-core/src/main/java/oshi/software/os/linux/LinuxOSVersionInfoEx.java @@ -146,7 +146,8 @@ private boolean readOsRelease() { // remove beginning and ending '"' characters, etc from // VERSION="14.04.4 LTS, Trusty Tahr" (Ubuntu style) // or VERSION="17 (Beefy Miracle)" (os-release doc style) - line = line.replace("VERSION=", "").replaceAll("^\"|\"$", "").trim(); + //line = line.replace("VERSION=", "").replaceAll("^\"|\"$", "").trim(); + line = ParseUtil.getDoubleQuoteStringValue(line).trim(); String[] split = line.split("[()]"); if (split.length <= 1) { // If no parentheses, check for Ubuntu's comma format @@ -162,7 +163,8 @@ private boolean readOsRelease() { LOG.debug("os-release: {}", line); // remove beginning and ending '"' characters, etc from // VERSION_ID="14.04" - this.version = line.replace("VERSION_ID=", "").replaceAll("^\"|\"$", "").trim(); + //this.version = line.replace("VERSION_ID=", "").replaceAll("^\"|\"$", "").trim(); + this.version = ParseUtil.getDoubleQuoteStringValue(line).trim(); } } } @@ -210,16 +212,19 @@ private boolean readLsbRelease() { for (String line : osRelease) { if (line.startsWith("DISTRIB_DESCRIPTION=")) { LOG.debug("lsb-release: {}", line); - line = line.replace("DISTRIB_DESCRIPTION=", "").replaceAll("^\"|\"$", "").trim(); + //line = line.replace("DISTRIB_DESCRIPTION=", "").replaceAll("^\"|\"$", "").trim(); + line = ParseUtil.getDoubleQuoteStringValue(line).trim(); if (line.contains(" release ")) { this.version = parseRelease(line, " release "); } } else if (line.startsWith("DISTRIB_RELEASE=") && this.version == null) { LOG.debug("lsb-release: {}", line); - this.version = line.replace("DISTRIB_RELEASE=", "").replaceAll("^\"|\"$", "").trim(); + //this.version = line.replace("DISTRIB_RELEASE=", "").replaceAll("^\"|\"$", "").trim(); + this.version = ParseUtil.getDoubleQuoteStringValue(line).trim(); } else if (line.startsWith("DISTRIB_CODENAME=") && this.codeName == null) { LOG.debug("lsb-release: {}", line); - this.codeName = line.replace("DISTRIB_CODENAME=", "").replaceAll("^\"|\"$", "").trim(); + //this.codeName = line.replace("DISTRIB_CODENAME=", "").replaceAll("^\"|\"$", "").trim(); + this.codeName = ParseUtil.getDoubleQuoteStringValue(line).trim(); } } } diff --git a/oshi-core/src/main/java/oshi/util/ParseUtil.java b/oshi-core/src/main/java/oshi/util/ParseUtil.java index 7f5bd9d46a9..32cecb12e22 100644 --- a/oshi-core/src/main/java/oshi/util/ParseUtil.java +++ b/oshi-core/src/main/java/oshi/util/ParseUtil.java @@ -491,11 +491,11 @@ public static String parseUuidOrDefault(String s, String defaultStr) { * @return the value contained between single tick marks */ public static String getSingleQuoteStringValue(String line) { - String[] split = line.split("'"); - if (split.length < 2) { - return ""; - } - return split[1]; + return getStringBetween(line , '\''); + } + + public static String getDoubleQuoteStringValue(String line) { + return getStringBetween(line , '"'); } /** diff --git a/oshi-core/src/test/java/oshi/util/ParseUtilTest.java b/oshi-core/src/test/java/oshi/util/ParseUtilTest.java index eb6efac800f..727ee94e5d8 100644 --- a/oshi-core/src/test/java/oshi/util/ParseUtilTest.java +++ b/oshi-core/src/test/java/oshi/util/ParseUtilTest.java @@ -28,7 +28,9 @@ /** * The Class ParseUtilTest. */ -public class ParseUtilTest { +public class ParseUtilTest +{ + /** * Test parse hertz. @@ -238,6 +240,12 @@ public void testGetSingleQuoteStringValue() { assertEquals("", ParseUtil.getSingleQuoteStringValue("foo = bar (string)")); } + @Test + public void testGetDoubleQuoteStringValue() { + assertEquals("bar" , ParseUtil.getDoubleQuoteStringValue("foo = \"bar\" (string)")); + assertEquals("", ParseUtil.getDoubleQuoteStringValue("hello")); + } + /** * Test parse SingleQuoteBetweenMultipleQuotes */