]> git.cameronkatri.com Git - cgit.git/commitdiff
Fix cgit_parse_url when a repo url is contained in another repo url
authorJulian Maurice <julian.maurice@biblibre.com>
Fri, 28 Mar 2014 22:18:29 +0000 (23:18 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 5 Apr 2014 22:05:36 +0000 (19:05 -0300)
For example, if I have two repos (remove-suffix is enabled):
  /foo
  /foo/bar

http://cgit/foo/bar/ is interpreted as "repository 'foo', command 'bar'"
instead of "repository 'foo/bar'"

parsing.c

index 599f61ead66d5c9c4f3c99cf4493d5af691367c2..5b4b1f4e58d034878831b19076a95e25683c748d 100644 (file)
--- a/parsing.c
+++ b/parsing.c
@@ -17,7 +17,8 @@
  */
 void cgit_parse_url(const char *url)
 {
-       char *cmd, *p;
+       char *c, *cmd, *p;
+       struct cgit_repo *repo;
 
        ctx.repo = NULL;
        if (!url || url[0] == '\0')
@@ -29,16 +30,20 @@ void cgit_parse_url(const char *url)
                return;
        }
 
-       cmd = strchr(url, '/');
-       while (!ctx.repo && cmd) {
-               cmd[0] = '\0';
-               ctx.repo = cgit_get_repoinfo(url);
-               if (ctx.repo == NULL) {
-                       cmd[0] = '/';
-                       cmd = strchr(cmd + 1, '/');
-                       continue;
+       cmd = NULL;
+       c = strchr(url, '/');
+       while (c) {
+               c[0] = '\0';
+               repo = cgit_get_repoinfo(url);
+               if (repo) {
+                       ctx.repo = repo;
+                       cmd = c;
                }
+               c[0] = '/';
+               c = strchr(c + 1, '/');
+       }
 
+       if (ctx.repo) {
                ctx.qry.repo = ctx.repo->url;
                p = strchr(cmd + 1, '/');
                if (p) {