[vlc-commits] url: Remove duplicated path separators
Hugo Beauzée-Luyssen
git at videolan.org
Mon Feb 24 09:38:23 CET 2020
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Feb 18 10:03:05 2020 +0100| [043988a2519f557856f14578b790da66283645fc] | 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
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=043988a2519f557856f14578b790da66283645fc
---
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 a3a7c77847..3912e1a78c 100644
--- a/src/test/url.c
+++ b/src/test/url.c
@@ -164,6 +164,16 @@ static void test_rfc3986(const char *reference, const char *expected)
test(vlc_uri_resolve_rfc3986_test, reference, 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);
@@ -375,6 +385,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 0c15a9bcb7..9e5eb6cff7 100644
--- a/src/text/url.c
+++ b/src/text/url.c
@@ -407,6 +407,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;
@@ -551,6 +571,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