Unverified Commit 5e7eb1d8 authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #641 from capnproto/harris/fix-relative-url-parse-bug

Fix bugs in relative URL parser
parents 542e75c2 cb69ee19
......@@ -369,6 +369,14 @@ KJ_TEST("parse relative URL") {
parseAndCheckRelative("https://capnproto.org/foo/bar?baz=qux#corge",
"/http:/grault",
"https://capnproto.org/http%3A/grault");
parseAndCheckRelative("https://capnproto.org/",
"/foo/../bar",
"https://capnproto.org/bar");
}
KJ_TEST("parse relative URL failure") {
auto base = Url::parse("https://example.com/");
KJ_EXPECT(base.tryParseRelative("https://[not a host]") == nullptr);
}
} // namespace
......
......@@ -279,6 +279,8 @@ Maybe<Url> Url::tryParseRelative(StringPtr text) const {
}
result.host = percentDecode(authority, err);
if (!HOST_CHARS.containsAll(result.host)) return nullptr;
toLower(result.host);
} else {
// copy authority
result.host = kj::str(this->host);
......@@ -310,7 +312,7 @@ Maybe<Url> Url::tryParseRelative(StringPtr text) const {
for (;;) {
auto part = split(text, END_PATH_PART);
if (part.size() == 2 && part[0] == '.' && part[1] == '.') {
if (path.size() != 0) {
if (result.path.size() != 0) {
result.path.removeLast();
}
result.hasTrailingSlash = true;
......
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