#include "url.h"
#include "host.h" /* for is_valid_ipv6_address */
+#ifdef TESTING
+#include "test.h"
+#endif
+
enum {
scm_disabled = 1, /* for https when OpenSSL fails to init. */
scm_has_params = 2, /* whether scheme has ;params */
}
assert (q - TAIL (dest) == outlen);
}
+
+ /* Perform inline case transformation if required. */
+ if (opt.restrict_files_case == restrict_lowercase
+ || opt.restrict_files_case == restrict_uppercase)
+ {
+ char *q;
+ for (q = TAIL (dest); *q; ++q)
+ {
+ if (opt.restrict_files_case == restrict_lowercase)
+ *q = TOLOWER (*q);
+ else
+ *q = TOUPPER (*q);
+ }
+ }
+
TAIL_INCR (dest, outlen);
}
{
char *h = path; /* hare */
char *t = path; /* tortoise */
- char *beg = path; /* boundary for backing the tortoise */
- char *end = path + strlen (path);
+ char *end = strchr (path, '\0');
while (h < end)
{
{
/* Handle "../" by retreating the tortoise by one path
element -- but not past beggining. */
- if (t > beg)
+ if (t > path)
{
/* Move backwards until T hits the beginning of the
previous path element or the beginning of path. */
- for (--t; t > beg && t[-1] != '/'; t--)
+ for (--t; t > path && t[-1] != '/'; t--)
;
}
- else
- {
- /* If we're at the beginning, copy the "../" literally
- move the beginning so a later ".." doesn't remove
- it. */
- beg = t + 3;
- goto regular;
- }
h += 3;
}
else
{
- regular:
/* A regular path element. If H hasn't advanced past T,
simply skip to the next path element. Otherwise, copy
the path element until the next slash. */
}
/* Find the last occurrence of character C in the range [b, e), or
- NULL, if none are present. We might want to use memrchr (a GNU
- extension) under GNU libc. */
-
-static const char *
-find_last_char (const char *b, const char *e, char c)
-{
- for (; e > b; e--)
- if (*e == c)
- return e;
- return NULL;
-}
+ NULL, if none are present. */
+#define find_last_char(b, e, c) memrchr ((b), (c), (e) - (b))
/* Merge BASE with LINK and return the resulting URI.
{ "", "", false },
{ ".", "", true },
{ "./", "", true },
- { "..", "..", false },
- { "../", "../", false },
+ { "..", "", true },
+ { "../", "", true },
{ "foo", "foo", false },
{ "foo/bar", "foo/bar", false },
{ "foo///bar", "foo///bar", false },
{ "foo/bar/../x", "foo/x", true },
{ "foo/bar/../x/", "foo/x/", true },
{ "foo/..", "", true },
- { "foo/../..", "..", true },
- { "foo/../../..", "../..", true },
- { "foo/../../bar/../../baz", "../../baz", true },
+ { "foo/../..", "", true },
+ { "foo/../../..", "", true },
+ { "foo/../../bar/../../baz", "baz", true },
{ "a/b/../../c", "c", true },
{ "./a/../b", "b", true }
};
}
}
#endif
+\f
+#ifdef TESTING
+
+const char *
+test_append_uri_pathel()
+{
+ int i;
+ struct {
+ char *original_url;
+ char *input;
+ bool escaped;
+ char *expected_result;
+ } test_array[] = {
+ { "http://www.yoyodyne.com/path/", "somepage.html", false, "http://www.yoyodyne.com/path/somepage.html" },
+ };
+
+ for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i)
+ {
+ struct growable dest;
+ const char *p = test_array[i].input;
+
+ memset (&dest, 0, sizeof (dest));
+
+ append_string (test_array[i].original_url, &dest);
+ append_uri_pathel (p, p + strlen(p), test_array[i].escaped, &dest);
+
+ mu_assert ("test_append_uri_pathel: wrong result",
+ strcmp (dest.base, test_array[i].expected_result) == 0);
+ }
+
+ return NULL;
+}
+
+#endif /* TESTING */
+