summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2024-04-17 08:19:40 +0000
committerDavid Kalnischkies <david@kalnischkies.de>2024-04-17 09:12:58 +0000
commit633f6d67a28b375cf1f225f14d3c926e618d46af (patch)
tree4bbd2ccb863183c60db61d5730f4d1c1e2eda069
parente68a7ee54a5aba11d0fde3384cc90a20b1d184a0 (diff)
Allow no spaces for the last dependency in ParseDepends, too
All other entries in a dependency line get substantial leeway about the amount of spaces surrounding the entry itself and its individual parts, but the very last entry was required to have a version constraint be at least 4 chars long (excluding opening bracket and spaces following it), so if the version is short and a single-char relation used a space had to make up for it. This is a bit unfair in comparison to the other entries who do not have such unreasonable demands, so we reduce our demand to 3 chars or longer, which is satisfied by "=1)". If it is a good idea to hate spaces that much remains unanswered by this commit, but in practice most tools (re)writing the files we parse will include spaces, so its only in files (or on the satisfy command line) directly edited by users that we can encounter such a situation, which is a relatively new development given this line came unchanged from the introduction of this method in 1998. LP: #2061834
-rw-r--r--apt-pkg/deb/deblistparser.cc2
-rw-r--r--test/libapt/parsedepends_test.cc33
2 files changed, 34 insertions, 1 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 46c362952..071189b04 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -608,7 +608,7 @@ const char *debListParser::ParseDepends(const char *Start, const char *Stop,
{
// Skip the '('
for (I++; I != Stop && isspace_ascii(*I) != 0 ; I++);
- if (I + 3 >= Stop)
+ if (I + 3 > Stop)
return 0;
I = ConvertRelation(I,Op);
diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc
index f641c8c1c..454908ef7 100644
--- a/test/libapt/parsedepends_test.cc
+++ b/test/libapt/parsedepends_test.cc
@@ -278,3 +278,36 @@ test:
if (runner < 8)
goto test; // this is the prove: tests are really evil ;)
}
+
+TEST(ParseDependsTest, SpaceHate)
+{
+ auto const *const Depends = "no(=1), some(<<1),some (<<1),some( <<1),some(<< 1),some(<<1 ),some(<<1) ,last (=1)";
+ const char* const End = Depends + strlen(Depends);
+
+ const char* Start = Depends;
+ std::string Package;
+ std::string Version;
+ unsigned int Op = 29;
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op);
+ EXPECT_NE(nullptr, Start);
+ EXPECT_EQ("no", Package);
+ EXPECT_EQ("1", Version);
+ EXPECT_EQ(pkgCache::Dep::Equals, Op);
+
+ for (int i = 0; i < 6; ++i)
+ {
+ SCOPED_TRACE(i);
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op);
+ EXPECT_NE(nullptr, Start);
+ EXPECT_EQ("some", Package);
+ EXPECT_EQ("1", Version);
+ EXPECT_EQ(pkgCache::Dep::Less, Op);
+ }
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op);
+ EXPECT_EQ(End, Start);
+ EXPECT_EQ("last", Package);
+ EXPECT_EQ("1", Version);
+ EXPECT_EQ(pkgCache::Dep::Equals, Op);
+}