commit f90d1c6a1e8b2b546440a59337a68e3b9338994c
parent 61e633fa6274df76bc0c7c756fcd73c0a0ebb94b
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 13 Feb 2016 15:23:17 -0500
fix version parsing for strings containing repeated digits
Diffstat:
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/version.cpp b/src/version.cpp
@@ -41,9 +41,10 @@ Version::Version(const std::string &str, Package *pkg)
if(begin == end || size > 4L)
throw reapack_error("invalid version name");
- for(sregex_iterator it = begin; it != end; it++) {
+ size_t index = 0;
+
+ for(sregex_iterator it = begin; it != end; it++, index++) {
const string match = it->str(1);
- const size_t index = distance(begin, it);
if(match.size() > 4)
throw reapack_error("version component overflow");
diff --git a/test/version.cpp b/test/version.cpp
@@ -59,6 +59,13 @@ TEST_CASE("version with 4 components", M) {
REQUIRE(ver < Version("1.2.4"));
}
+TEST_CASE("version with repeated digits", M) {
+ Version ver("1.1.1");
+ REQUIRE(ver.name() == "1.1.1");
+ REQUIRE(ver.code() == UINT64_C(1000100010000));
+ REQUIRE(ver < Version("1.1.2"));
+}
+
TEST_CASE("decimal version", M) {
Version ver("5.05");
REQUIRE(ver == Version("5.5"));