diff --git a/mongoose.c b/mongoose.c index 5fa11f4c..81b85646 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2430,7 +2430,9 @@ static void remove_double_dots_and_double_slashes(char *s) { // Skip all following slashes, backslashes and double-dots while (s[0] != '\0') { if (s[0] == '/' || s[0] == '\\') { s++; } - else if (s[0] == '.' && s[1] == '.') { s += 2; } + else if (s[0] == '.' && (s[1] == '/' || s[1] == '\\')) { s += 2; } + else if (s[0] == '.' && s[1] == '.' && s[2] == '\0') { s += 2; } + else if (s[0] == '.' && s[1] == '.' && (s[2] == '/' || s[2] == '\\')) { s += 3; } else { break; } } } diff --git a/test/unit_test.c b/test/unit_test.c index cda17b12..c3153aca 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -198,17 +198,19 @@ static const char *test_match_prefix(void) { } static const char *test_remove_double_dots() { - struct { char before[20], after[20]; } data[] = { + struct { char before[30], after[30]; } data[] = { {"////a", "/a"}, - {"/.....", "/."}, - {"/......", "/"}, + {"/.....", "/....."}, + {"/......", "/......"}, {"...", "..."}, - {"/...///", "/./"}, + {"/...///", "/.../"}, {"/a...///", "/a.../"}, {"/.x", "/.x"}, {"/\\", "/"}, {"/a\\", "/a\\"}, - {"/a\\\\...", "/a\\."}, + {"/a\\\\...", "/a\\..."}, + {"foo/x..y/././y/../../..", "foo/x..y/y/"}, + {"foo/..x", "foo/..x"}, }; size_t i;