From 6a9589b4a1f5cdedbbfbb13ced54d8a473d8cbd7 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 8 Feb 2021 22:12:31 +0100 Subject: [PATCH] Fix dependency matching if pkgrel contains a dot --- libpkg/data/package.cpp | 19 ++++++++++--------- libpkg/tests/data.cpp | 11 ++++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/libpkg/data/package.cpp b/libpkg/data/package.cpp index 29426df..8ee0dae 100644 --- a/libpkg/data/package.cpp +++ b/libpkg/data/package.cpp @@ -227,17 +227,18 @@ PackageVersionPartComparison PackageVersion::compareParts(const string &part1, c part2Pos = part2End + 1; } else if (*part1End) { // only part 1 has another segment -> it is more specific and hence considered newer - if (allowImplicitPkgRel) { - // check whether the only further segment in part 1 is pkgrel - // -> check for pkgrel separation which is always '-' - if (*part1End == '-') { - part1Pos = part1End + 1; - part1End = firstNonAlphanumericCharacter(part1Pos, part1End); - if (!*part1End) { - // consider both parts equal if part 2 doesn't have explicit pkgrel and part 1 does - return PackageVersionPartComparison::Equal; + if (allowImplicitPkgRel && *part1End == '-') { + // check whether the only further segment in part 1 is pkgrel (starts with '-' and only contains alphanumeric chars and '.') + for (part1Pos = part1End + 1; part1Pos != part1End; ++part1Pos) { + const char c = *part1Pos; + if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '.'))) { + break; } } + if (!*part1Pos) { + // consider both parts equal if part 2 doesn't have explicit pkgrel and part 1 does + return PackageVersionPartComparison::Equal; + } } return PackageVersionPartComparison::Newer; } else if (*part2End) { diff --git a/libpkg/tests/data.cpp b/libpkg/tests/data.cpp index 250a450..5c00cd6 100644 --- a/libpkg/tests/data.cpp +++ b/libpkg/tests/data.cpp @@ -188,12 +188,17 @@ void DataTests::testDependencyMatching() CPPUNIT_ASSERT_MESSAGE( "greather equal constraint with explicitely specified pkgrel must match", pkg3.providesDependency(Dependency::fromString(depStr, 17))); - Package pkg4; + pkg3.name = "sphinxbase"; + pkg3.version = "5prealpha-11.1aBc"; + depStr = "sphinxbase=5prealpha"; + CPPUNIT_ASSERT_MESSAGE( + "equal constraint, any pkgrel should match (even strange one)", pkg3.providesDependency(Dependency::fromString(depStr, 20))); + pkg3.name = "ffmpeg"; pkg3.version = "1:4.1-3"; - CPPUNIT_ASSERT(pkg3.providesDependency(Dependency::fromString("ffmpeg<1:4.3"))); + CPPUNIT_ASSERT_MESSAGE("real-world ffmpeg example (1)", pkg3.providesDependency(Dependency::fromString("ffmpeg<1:4.3"))); pkg3.version = "1:4.1-2"; - CPPUNIT_ASSERT(!pkg3.providesDependency(Dependency::fromString("ffmpeg>=1:4.1-3"))); + CPPUNIT_ASSERT_MESSAGE("real-world ffmpeg example (2)", !pkg3.providesDependency(Dependency::fromString("ffmpeg>=1:4.1-3"))); } void DataTests::testPackageSearch()