Commit c2ff2eb3 authored by Harris Hancock's avatar Harris Hancock

Use new URL component encoding functions in kj::Url

This has the effect of making the authority, path, and fragment components each slightly more permissive in what they don't escape.
No related merge requests found
......@@ -198,11 +198,11 @@ KJ_TEST("parse / stringify URL") {
}
{
auto url = parseAndCheck("https://foo:1234@capnproto.org");
auto url = parseAndCheck("https://$foo&:12+,34@capnproto.org");
KJ_EXPECT(url.scheme == "https");
auto& user = KJ_ASSERT_NONNULL(url.userInfo);
KJ_EXPECT(user.username == "foo");
KJ_EXPECT(KJ_ASSERT_NONNULL(user.password) == "1234");
KJ_EXPECT(user.username == "$foo&");
KJ_EXPECT(KJ_ASSERT_NONNULL(user.password) == "12+,34");
KJ_EXPECT(url.host == "capnproto.org");
KJ_EXPECT(url.path == nullptr);
KJ_EXPECT(!url.hasTrailingSlash);
......@@ -221,6 +221,11 @@ KJ_TEST("parse / stringify URL") {
KJ_EXPECT(url.fragment == nullptr);
}
{
auto url = parseAndCheck("https://capnproto.org/foo%2Fbar/baz");
KJ_EXPECT(url.path.asPtr() == kj::ArrayPtr<const StringPtr>({"foo/bar", "baz"}));
}
parseAndCheck("https://capnproto.org/foo/bar?", "https://capnproto.org/foo/bar");
parseAndCheck("https://capnproto.org/foo/bar?#", "https://capnproto.org/foo/bar#");
parseAndCheck("https://capnproto.org/foo/bar#");
......@@ -241,6 +246,15 @@ KJ_TEST("URL percent encoding") {
parseAndCheck(
"https://b b: bcd@capnproto.org/f o?b r=b z#q x",
"https://b%20b:%20bcd@capnproto.org/f%20o?b+r=b+z#q%20x");
parseAndCheck(
"https://capnproto.org/foo?bar=baz#@?#^[\\]{|}",
"https://capnproto.org/foo?bar=baz#@?#^[\\]{|}");
// All permissible non-alphanumeric, non-separator path characters.
parseAndCheck(
"https://capnproto.org/!$&'()*+,-.:;=@[]^_|~",
"https://capnproto.org/!$&'()*+,-.:;=@[]^_|~");
}
KJ_TEST("URL relative paths") {
......@@ -368,7 +382,7 @@ KJ_TEST("parse relative URL") {
"http://capnproto.org/grault");
parseAndCheckRelative("https://capnproto.org/foo/bar?baz=qux#corge",
"/http:/grault",
"https://capnproto.org/http%3A/grault");
"https://capnproto.org/http:/grault");
parseAndCheckRelative("https://capnproto.org/",
"/foo/../bar",
"https://capnproto.org/bar");
......
......@@ -375,10 +375,10 @@ String Url::toString(Context context) const {
if (context == REMOTE_HREF) {
KJ_IF_MAYBE(user, userInfo) {
chars.addAll(encodeUriComponent(user->username));
chars.addAll(encodeUriUserInfo(user->username));
KJ_IF_MAYBE(pass, user->password) {
chars.add(':');
chars.addAll(encodeUriComponent(*pass));
chars.addAll(encodeUriUserInfo(*pass));
}
chars.add('@');
}
......@@ -407,7 +407,7 @@ String Url::toString(Context context) const {
continue;
}
chars.add('/');
chars.addAll(encodeUriComponent(pathPart));
chars.addAll(encodeUriPath(pathPart));
}
if (hasTrailingSlash || (path.size() == 0 && context == HTTP_REQUEST)) {
chars.add('/');
......@@ -427,7 +427,7 @@ String Url::toString(Context context) const {
if (context == REMOTE_HREF) {
KJ_IF_MAYBE(f, fragment) {
chars.add('#');
chars.addAll(encodeUriComponent(*f));
chars.addAll(encodeUriFragment(*f));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment