diff --git a/src/utility.cpp b/src/utility.cpp index e50b0fe..c2aeece 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -316,6 +316,10 @@ int Natural::compare(const std::string &s1, const std::string &s2) { size_t i1 = 0; size_t i2 = 0; while(i1 < s1.size() && i2 < s2.size()) { + if(s1[i1] == '.' && s2[i2] != '.') + return -1; + if(s1[i1] != '.' && s2[i2] == '.') + return 1; if(is_digit(s1[i1]) && !is_digit(s2[i2])) return -1; if(!is_digit(s1[i1]) && is_digit(s2[i2])) diff --git a/tests/utility_test.cpp b/tests/utility_test.cpp index c86fcd9..0733344 100644 --- a/tests/utility_test.cpp +++ b/tests/utility_test.cpp @@ -198,4 +198,10 @@ int main() { g_assert(Natural::compare("z2", "z11") == -1); g_assert(Natural::compare("z11", "z2") == 1); } + { + g_assert(Natural::compare("t", "t1") == -1); + g_assert(Natural::compare("t.txt", "t1.txt") == -1); + g_assert(Natural::compare("t1", "t") == 1); + g_assert(Natural::compare("t1.txt", "t.txt") == 1); + } }