[vlc-commits] url: Remove duplicated path separators

Hugo Beauzée-Luyssen git at videolan.org
Wed Feb 26 15:36:53 CET 2020


vlc/vlc-3.0 | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Feb 18 10:03:05 2020 +0100| [7f204ee4b414ee479428ce0e926fd06c7023e649] | committer: Hugo Beauzée-Luyssen

url: Remove duplicated path separators

Otherwise the doted segments removal may be confused.
For instance vlc_uri_resolve("scheme:///a/b/c//file.ext", "../folder")
would return scheme:///a/b/c/folder instead of scheme:///a/b/folder

(cherry picked from commit 043988a2519f557856f14578b790da66283645fc)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=7f204ee4b414ee479428ce0e926fd06c7023e649
---

 src/test/url.c | 20 ++++++++++++++++++++
 src/text/url.c | 21 +++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/src/test/url.c b/src/test/url.c
index ab02571ac7..e170d8b0ab 100644
--- a/src/test/url.c
+++ b/src/test/url.c
@@ -158,6 +158,16 @@ static void test_fixup_noop(const char *expected)
     test(vlc_uri_fixup, expected, expected);
 }
 
+static char *vlc_uri_resolve_separators_test(const char *in)
+{
+    return vlc_uri_resolve("file:///a/b/c//d.ext", in);
+}
+
+static void test_separators(const char *reference, const char *expected)
+{
+    test(vlc_uri_resolve_separators_test, reference, expected);
+}
+
 int main (void)
 {
     (void)setvbuf (stdout, NULL, _IONBF, 0);
@@ -363,6 +373,16 @@ int main (void)
 
     for (size_t i = 0; i < ARRAY_SIZE(rfc3986_cases); i += 2)
         test_rfc3986(rfc3986_cases[i], rfc3986_cases[i + 1]);
+    static const char* separators_patterns[] = {
+        "../",                      "file:///a/b/",
+        "./",                       "file:///a/b/c/",
+        "../../../../../../../",    "file:///",
+        "..///////////////",        "file:///a/b/",
+        ".///////////////",         "file:///a/b/c/",
+        "..//..//",                 "file:///a/",
+    };
+    for (size_t i = 0; i < ARRAY_SIZE(separators_patterns); i += 2)
+        test_separators(separators_patterns[i], separators_patterns[i + 1]);
 
     /* Check that fixup does not mangle valid URIs */
     static const char *valid_uris[] =
diff --git a/src/text/url.c b/src/text/url.c
index 83bba30e09..c3c36015d7 100644
--- a/src/text/url.c
+++ b/src/text/url.c
@@ -401,6 +401,26 @@ static bool vlc_uri_path_validate(const char *str)
     return vlc_uri_component_validate(str, "/@:");
 }
 
+static void vlc_uri_fixup_duplicated_separators(char *str)
+{
+    if (str == NULL)
+        return;
+    char *input = str, *output = str;
+    while (*input)
+    {
+        assert(input >= output);
+        if (*input == '/')
+        {
+            *output++ = *input;
+            while (*input == '/')
+                input++;
+        }
+        else
+            *output++ = *input++;
+    }
+    *output = 0;
+}
+
 static int vlc_UrlParseInner(vlc_url_t *restrict url, const char *str)
 {
     url->psz_protocol = NULL;
@@ -548,6 +568,7 @@ static int vlc_UrlParseInner(vlc_url_t *restrict url, const char *str)
     {
         url->psz_path = cur;
     }
+    vlc_uri_fixup_duplicated_separators(url->psz_path);
 
     return ret;
 }



More information about the vlc-commits mailing list