diff --git a/Changelog.md b/Changelog.md index d491e6f72..0247137b3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -18,7 +18,7 @@ Bugfixes: * SMTChecker: Fix internal error when using ``abi.decode``. * SMTChecker: Fix internal error when using arrays or mappings of functions. * SMTChecker: Fix internal error in array of structs type. - * Version Checker: 0.5.x-prerelease will match `pragma solidity ^0.5`. + * Version Checker: ``^0`` should match ``0.5.0``, but no prerelease. * Yul: Consider infinite loops and recursion to be not removable. diff --git a/liblangutil/SemVerHandler.cpp b/liblangutil/SemVerHandler.cpp index 611f058ae..cc414b1d7 100644 --- a/liblangutil/SemVerHandler.cpp +++ b/liblangutil/SemVerHandler.cpp @@ -88,7 +88,7 @@ bool SemVerMatchExpression::MatchComponent::matches(SemVerVersion const& _versio if (!comp.matches(_version)) return false; - if (comp.version.numbers[0] == 0) + if (comp.version.numbers[0] == 0 && comp.levelsPresent != 1) comp.levelsPresent = 2; else comp.levelsPresent = 1; @@ -107,17 +107,7 @@ bool SemVerMatchExpression::MatchComponent::matches(SemVerVersion const& _versio } if (cmp == 0 && !_version.prerelease.empty() && didCompare) - { cmp = -1; - for (unsigned i = levelsPresent; i < 3; i++) - { - if (_version.numbers[i] > 0) - { - cmp = 0; - break; - } - } - } switch (prefix) { diff --git a/test/libsolidity/SemVerMatcher.cpp b/test/libsolidity/SemVerMatcher.cpp index 7dae613a8..e0e643968 100644 --- a/test/libsolidity/SemVerMatcher.cpp +++ b/test/libsolidity/SemVerMatcher.cpp @@ -141,14 +141,14 @@ BOOST_AUTO_TEST_CASE(positive_range) {"^0.1.2", "0.1.2"}, {"^0.1", "0.1.2"}, {"^1.2", "1.4.2"}, - {"^1.2", "1.2.1-pre"}, {"^1.2", "1.2.0"}, - {"^1", "1.2.0-pre"}, {"^1", "1.2.0"}, {"<=1.2.3", "1.2.3-beta"}, {">1.2", "1.3.0-beta"}, {"<1.2.3", "1.2.3-beta"}, - {"^1.2 ^1", "1.4.2"} + {"^1.2 ^1", "1.4.2"}, + {"^0", "0.5.1"}, + {"^0", "0.1.1"}, }; for (auto const& t: tests) { @@ -163,13 +163,14 @@ BOOST_AUTO_TEST_CASE(positive_range) BOOST_AUTO_TEST_CASE(negative_range) { - // Positive range tests + // Negative range tests vector> tests = { {"1.0.0 - 2.0.0", "2.2.3"}, {"1.0", "1.0.0-pre"}, {"1", "1.0.0-pre"}, {"^1.2.3", "1.2.3-pre"}, {"^1.2", "1.2.0-pre"}, + {"^1.2", "1.2.1-pre"}, {"^1.2.3", "1.2.3-beta"}, {"=0.7.x", "0.7.0-asdf"}, {">=0.7.x", "0.7.0-asdf"}, @@ -212,8 +213,16 @@ BOOST_AUTO_TEST_CASE(negative_range) {"=1.2.3", "1.2.3-beta"}, {">1.2", "1.2.8"}, {"^1.2.3", "2.0.0-alpha"}, + {"^0.6", "0.6.2-alpha"}, + {"^0.6", "0.6.0-alpha"}, + {"^1.2", "1.2.1-pre"}, {"^1.2.3", "1.2.2"}, - {"^1.2", "1.1.9"} + {"^1", "1.2.0-pre"}, + {"^1", "1.2.0-pre"}, + {"^1.2", "1.1.9"}, + {"^0", "0.5.1-pre"}, + {"^0", "0.0.0-pre"}, + {"^0", "1.0.0"}, }; for (auto const& t: tests) {