Skip to content
This repository has been archived by the owner on Sep 23, 2022. It is now read-only.

Commit

Permalink
Remove repeating backslashes only on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Feb 9, 2012
1 parent 84a76fb commit 9d3af98
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions test/\/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blah
5 changes: 3 additions & 2 deletions test/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ sub kill_spawned_child {
write_file("$root/a+.txt", '');
o("GET /a+.txt HTTP/1.0\n\n", 'HTTP/1.1 200 OK', 'URL-decoding, + in URI');

#o("GET /hh HTTP/1.0\n\n", 'HTTP/1.1 200 OK', 'GET admin URI');
o("GET /%5c/a.txt HTTP/1.0\n\n", 'blah', 'GET dir backslash');

# Test HTTP version parsing
o("GET / HTTPX/1.0\r\n\r\n", '400 Bad Request', 'Bad HTTP Version', 0);
Expand All @@ -213,7 +213,8 @@ sub kill_spawned_child {
# File with leading single dot
o("GET /.leading.dot.txt HTTP/1.0\n\n", 'abc123', 'Leading dot 1');
o("GET /...leading.dot.txt HTTP/1.0\n\n", 'abc123', 'Leading dot 2');
o("GET /../\\\\/.//...leading.dot.txt HTTP/1.0\n\n", 'abc123', 'Leading dot 3');
o("GET /../\\\\/.//...leading.dot.txt HTTP/1.0\n\n", 'abc123', 'Leading dot 3')
if on_windows();
o("GET .. HTTP/1.0\n\n", '400 Bad Request', 'Leading dot 4', 0);

mkdir $test_dir unless -d $test_dir;
Expand Down
31 changes: 30 additions & 1 deletion test/unit_test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "mongoose.c"

int main(void) {
static void test_match_prefix(void) {
assert(match_prefix("/a/", 3, "/a/b/c") == 3);
assert(match_prefix("/a/", 3, "/ab/c") == -1);
assert(match_prefix("/*/", 3, "/ab/c") == 4);
Expand All @@ -25,6 +25,35 @@ int main(void) {
assert(match_prefix("**.a$|**.b$", 11, "/a/b.b/") == -1);
assert(match_prefix("**.a$|**.b$", 11, "/a/b.b") == 6);
assert(match_prefix("**.a$|**.b$", 11, "/a/b.a") == 6);
}

static void test_remove_double_dots() {
struct { char before[20], after[20]; } data[] = {
{"////a", "/a"},
{"/.....", "/."},
{"/......", "/"},
{"...", "..."},
{"/...///", "/./"},
{"/a...///", "/a.../"},
{"/.x", "/.x"},
#if defined(_WIN32)
{"/\\", "/"},
#else
{"/\\", "/\\"},
#endif
{"/a\\", "/a\\"},
};
size_t i;

for (i = 0; i < ARRAY_SIZE(data); i++) {
//printf("[%s] -> [%s]\n", data[i].before, data[i].after);
remove_double_dots_and_double_slashes(data[i].before);
assert(strcmp(data[i].before, data[i].after) == 0);
}
}

int main(void) {
test_match_prefix();
test_remove_double_dots();
return 0;
}

0 comments on commit 9d3af98

Please sign in to comment.