]> git.saurik.com Git - apt.git/commitdiff
deal with empty values properly in deb822 parser
authorDavid Kalnischkies <david@kalnischkies.de>
Sun, 27 Dec 2015 20:52:01 +0000 (21:52 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Sun, 27 Dec 2015 20:52:01 +0000 (21:52 +0100)
Regression introduced in 8710a36a01c0cb1648926792c2ad05185535558e,
but such fields are unlikely in practice as it is just as simple to not
have a field at all with the same result of not having a value.

Closes: 808102
apt-pkg/tagfile.cc
test/libapt/tagfile_test.cc

index 668cfc3a42e71d250e9562e40d14cad9c8c17ccd..a0b64f9ca812f95686366dffbe9cf1d57118d755 100644 (file)
@@ -382,7 +382,9 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const R
         lastTagHash = AlphaHash(Stop, EndTag - Stop);
         // find the beginning of the value
         Stop = Colon + 1;
-        for (; isspace_ascii(*Stop) != 0; ++Stop);
+        for (; isspace_ascii(*Stop) != 0; ++Stop)
+           if (*Stop == '\n' && Stop[1] != ' ')
+              break;
         if (Stop >= End)
            return false;
         lastTagData.StartValue = Stop - Section;
index d7030f41a2723a8144925b7e0b6f8524d11224fc..064e91b799aa46e6d4fc4c11ee4d0d05b7f6ab9e 100644 (file)
@@ -186,6 +186,7 @@ TEST(TagFileTest, SpacesEverywhere)
       "Package: pkgA\n"
       "Package: pkgB\n"
       "NoSpaces:yes\n"
+      "NoValue:\n"
       "TagSpaces\t    :yes\n"
       "ValueSpaces:   \tyes\n"
       "BothSpaces     \t:\t   yes\n"
@@ -200,6 +201,7 @@ TEST(TagFileTest, SpacesEverywhere)
    EXPECT_TRUE(section.Scan(content.c_str(), content.size()));
    EXPECT_TRUE(section.Exists("Package"));
    EXPECT_TRUE(section.Exists("NoSpaces"));
+   EXPECT_TRUE(section.Exists("NoValue"));
    EXPECT_TRUE(section.Exists("TagSpaces"));
    EXPECT_TRUE(section.Exists("ValueSpaces"));
    EXPECT_TRUE(section.Exists("BothSpaces"));
@@ -209,6 +211,7 @@ TEST(TagFileTest, SpacesEverywhere)
    EXPECT_TRUE(section.Exists("Multi-Colon"));
    EXPECT_EQ("pkgC", section.FindS("Package"));
    EXPECT_EQ("yes", section.FindS("NoSpaces"));
+   EXPECT_EQ("", section.FindS("NoValue"));
    EXPECT_EQ("yes", section.FindS("TagSpaces"));
    EXPECT_EQ("yes", section.FindS("ValueSpaces"));
    EXPECT_EQ("yes", section.FindS("BothSpaces"));
@@ -217,5 +220,5 @@ TEST(TagFileTest, SpacesEverywhere)
    EXPECT_EQ("yes", section.FindS("Naming  Spaces"));
    EXPECT_EQ(":yes:", section.FindS("Multi-Colon"));
    // overridden values are still present, but not really accessible
-   EXPECT_EQ(11, section.Count());
+   EXPECT_EQ(12, section.Count());
 }