Version: support CRLF line feed in MANIFEST

When a MANIFEST is generated from Windows and it contains CRLF as line
feed, the code was getting each line with '\r' at the end, and thus the
parsed string contains '\r' and it incorrectly parses the string.

Add a piece of code to support CRLF line feed so support such MANIFEST
files.

Tested: Added a unit test case to verify CRLF is correctly handled.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I99e146717b815e3e40c232376555b2b48d77bc56
diff --git a/src/version.cpp b/src/version.cpp
index ecefc98..b6ca139 100644
--- a/src/version.cpp
+++ b/src/version.cpp
@@ -39,6 +39,11 @@
 
     while (getline(efile, line))
     {
+        if (!line.empty() && line.back() == '\r')
+        {
+            // Remove \r from the end of line
+            line.pop_back();
+        }
         for (const auto& key : keys)
         {
             auto value = key + "=";
diff --git a/test/test_version.cpp b/test/test_version.cpp
index 8481952..431afc0 100644
--- a/test/test_version.cpp
+++ b/test/test_version.cpp
@@ -17,6 +17,12 @@
 extended_version=model=dummy_model,manufacture=dummy_manufacture)";
 }
 
+constexpr auto validManifestWithCRLF =
+    "\r\n"
+    "purpose=xyz.openbmc_project.Software.Version.VersionPurpose.PSU\r\n"
+    "version=psu-dummy-test.v0.1\r\n"
+    "extended_version=model=dummy_model,manufacture=dummy_manufacture\r\n";
+
 class TestVersion : public ::testing::Test
 {
   public:
@@ -78,3 +84,20 @@
     EXPECT_EQ("TestManu", ret["manufacturer"]);
     EXPECT_EQ("TestModel", ret["model"]);
 }
+
+TEST_F(TestVersion, getValuesOKonCRLFFormat)
+{
+    auto manifestFilePath = fs::path(tmpDir) / "MANIFEST";
+    writeFile(manifestFilePath, validManifestWithCRLF);
+    auto ret = Version::getValues(manifestFilePath.string(),
+                                  {"purpose", "version", "extended_version"});
+    EXPECT_EQ(3u, ret.size());
+    auto purpose = ret["purpose"];
+    auto version = ret["version"];
+    auto extVersion = ret["extended_version"];
+
+    EXPECT_EQ("xyz.openbmc_project.Software.Version.VersionPurpose.PSU",
+              purpose);
+    EXPECT_EQ("psu-dummy-test.v0.1", version);
+    EXPECT_EQ("model=dummy_model,manufacture=dummy_manufacture", extVersion);
+}