utils: add proper handling of "/" special case in uh_path_match()
authorJo-Philipp Wich <jo@mein.io>
Tue, 25 Oct 2016 14:23:05 +0000 (16:23 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 25 Oct 2016 14:32:50 +0000 (16:32 +0200)
The special prefix of "/" should match any url by definition but the final
assertion which ensures that the matched prefix ends in '\0' or '/' is causing
matches against the "/" prefix to fail.

Add some extra code to handle this special case to implemented the expected
behaviour.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
utils.c

diff --git a/utils.c b/utils.c
index 29e03c0..9342eb6 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -208,6 +208,10 @@ bool uh_path_match(const char *prefix, const char *url)
 {
        int len = strlen(prefix);
 
+       /* A prefix of "/" will - by definition - match any url */
+       if (prefix[0] == '/' && len == 1)
+               return true;
+
        if (strncmp(url, prefix, len) != 0)
                return false;