Commit 5e1a06fd authored by Kenton Varda's avatar Kenton Varda

Don't add an empty path component on trailing slash.

parent a358282e
......@@ -294,6 +294,18 @@ KJ_TEST("parse / stringify URL") {
// "." and ".." are still processed, though.
parseAndCheck("https://capnproto.org/foo//../bar/.",
"https://capnproto.org/foo/bar/", ALLOW_EMPTY);
{
auto url = parseAndCheck("https://foo/", nullptr, ALLOW_EMPTY);
KJ_EXPECT(url.path.size() == 0);
KJ_EXPECT(url.hasTrailingSlash);
}
{
auto url = parseAndCheck("https://foo/bar/", nullptr, ALLOW_EMPTY);
KJ_EXPECT(url.path.size() == 1);
KJ_EXPECT(url.hasTrailingSlash);
}
}
KJ_TEST("URL percent encoding") {
......
......@@ -233,7 +233,8 @@ Maybe<Url> Url::tryParse(StringPtr text, Context context, Options options) {
result.path.removeLast();
}
result.hasTrailingSlash = true;
} else if ((part.size() == 0 && !options.allowEmpty) || (part.size() == 1 && part[0] == '.')) {
} else if ((part.size() == 0 && (!options.allowEmpty || text.size() == 0)) ||
(part.size() == 1 && part[0] == '.')) {
// Collapse consecutive slashes and "/./".
result.hasTrailingSlash = true;
} else {
......
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