Commit bf7a115b authored by Sergey Lyubka's avatar Sergey Lyubka

Fix url rewrites

parent b8dfb69c
...@@ -40,7 +40,9 @@ ...@@ -40,7 +40,9 @@
#define DIRSEP '\\' #define DIRSEP '\\'
#define snprintf _snprintf #define snprintf _snprintf
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#ifndef sleep
#define sleep(x) Sleep((x) * 1000) #define sleep(x) Sleep((x) * 1000)
#endif
#define abs_path(rel, abs, abs_size) _fullpath((abs), (rel), (abs_size)) #define abs_path(rel, abs, abs_size) _fullpath((abs), (rel), (abs_size))
#define SIGCHLD 0 #define SIGCHLD 0
typedef struct _stat file_stat_t; typedef struct _stat file_stat_t;
......
...@@ -2681,7 +2681,8 @@ static int convert_uri_to_file_name(struct connection *conn, char *buf, ...@@ -2681,7 +2681,8 @@ static int convert_uri_to_file_name(struct connection *conn, char *buf,
#endif #endif
const char *uri = conn->mg_conn.uri; const char *uri = conn->mg_conn.uri;
const char *domain = mg_get_header(&conn->mg_conn, "Host"); const char *domain = mg_get_header(&conn->mg_conn, "Host");
size_t match_len, root_len = root == NULL ? 0 : strlen(root); // Important: match_len has to be declared as int, unless rewrites break.
int match_len, root_len = root == NULL ? 0 : strlen(root);
// Perform virtual hosting rewrites // Perform virtual hosting rewrites
if (rewrites != NULL && domain != NULL) { if (rewrites != NULL && domain != NULL) {
......
...@@ -169,6 +169,7 @@ static const char *test_match_prefix(void) { ...@@ -169,6 +169,7 @@ static const char *test_match_prefix(void) {
ASSERT(mg_match_prefix("/api", 4, "/api") == 4); ASSERT(mg_match_prefix("/api", 4, "/api") == 4);
ASSERT(mg_match_prefix("/a/", 3, "/a/b/c") == 3); ASSERT(mg_match_prefix("/a/", 3, "/a/b/c") == 3);
ASSERT(mg_match_prefix("/a/", 3, "/ab/c") == -1); ASSERT(mg_match_prefix("/a/", 3, "/ab/c") == -1);
ASSERT(mg_match_prefix("/blog/", 6, "/") == -1);
ASSERT(mg_match_prefix("/*/", 3, "/ab/c") == 4); ASSERT(mg_match_prefix("/*/", 3, "/ab/c") == 4);
ASSERT(mg_match_prefix("**", 2, "/a/b/c") == 6); ASSERT(mg_match_prefix("**", 2, "/a/b/c") == 6);
ASSERT(mg_match_prefix("/*", 2, "/a/b/c") == 2); ASSERT(mg_match_prefix("/*", 2, "/a/b/c") == 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment