Merge pull request #866 from kiwix/uri_encoded_redirections

This commit is contained in:
Matthieu Gautier 2023-01-10 15:06:18 +01:00 committed by GitHub
commit 7a98878273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 15 deletions

View File

@ -1030,7 +1030,7 @@ ParameterizedMessage suggestSearchMsg(const std::string& searchURL, const std::s
std::unique_ptr<Response>
InternalServer::build_redirect(const std::string& bookName, const zim::Item& item) const
{
const auto path = kiwix::urlEncode(item.getPath());
const auto path = kiwix::urlEncode(item.getPath(), true);
const auto redirectUrl = m_root + "/content/" + bookName + "/" + path;
return Response::build_redirect(*this, redirectUrl);
}

Binary file not shown.

View File

@ -0,0 +1 @@
wtf?.html

1
test/data/corner_cases/wtf? Symbolic link
View File

@ -0,0 +1 @@
wtf?.html

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WTF?</title>
</head>
<body>
<p>WTF? is an acronym coined by cryptography and security researcher Walter
Thomas Freiwald. It stands for "Will They Factorize?"</p>
</body>
</html>

View File

@ -2,13 +2,14 @@
cd "$(dirname "$0")"
rm -f corner_cases.zim
zimwriterfs -w empty.html \
-f empty.png \
-l=en \
-t="ZIM corner cases" \
-d="" \
-c="" \
-p="" \
zimwriterfs --withoutFTIndex --dont-check-arguments \
-w empty.html \
-I empty.png \
-l en \
-t "ZIM corner cases" \
-d "" \
-c "" \
-p "" \
corner_cases \
corner_cases.zim \
&& echo 'corner_cases.zim was successfully created' \

View File

@ -78,7 +78,6 @@ const ResourceCollection resources200Compressible{
{ DYNAMIC_CONTENT, "/ROOT/catalog/search" },
{ DYNAMIC_CONTENT, "/ROOT/catalog/v2/root.xml" },
{ DYNAMIC_CONTENT, "/ROOT/catalog/v2/languages" },
{ DYNAMIC_CONTENT, "/ROOT/catalog/v2/entries" },
{ DYNAMIC_CONTENT, "/ROOT/catalog/v2/partial_entries" },
@ -150,6 +149,7 @@ const ResourceCollection resources200Uncompressible{
{ DYNAMIC_CONTENT, "/ROOT/catalog/searchdescription.xml" },
{ DYNAMIC_CONTENT, "/ROOT/catalog/v2/categories" },
{ DYNAMIC_CONTENT, "/ROOT/catalog/v2/languages" },
{ DYNAMIC_CONTENT, "/ROOT/catalog/v2/searchdescription.xml" },
{ DYNAMIC_CONTENT, "/ROOT/catalog/v2/illustration/6f1d19d0-633f-087b-fb55-7ac324ff9baf?size=48" },
@ -157,9 +157,9 @@ const ResourceCollection resources200Uncompressible{
{ ZIM_CONTENT, "/ROOT/content/zimfile/I/m/Ray_Charles_classic_piano_pose.jpg" },
{ ZIM_CONTENT, "/ROOT/content/corner_cases/A/empty.html" },
{ ZIM_CONTENT, "/ROOT/content/corner_cases/-/empty.css" },
{ ZIM_CONTENT, "/ROOT/content/corner_cases/-/empty.js" },
{ ZIM_CONTENT, "/ROOT/content/corner_cases/empty.html" },
{ ZIM_CONTENT, "/ROOT/content/corner_cases/empty.css" },
{ ZIM_CONTENT, "/ROOT/content/corner_cases/empty.js" },
// The following url's responses are too small to be compressed
@ -1145,7 +1145,7 @@ TEST_F(ServerTest, RandomPageRedirectsToAnExistingArticle)
auto g = zfs1_->GET("/ROOT/random?content=zimfile");
ASSERT_EQ(302, g->status);
ASSERT_TRUE(g->has_header("Location"));
ASSERT_TRUE(kiwix::startsWith(g->get_header_value("Location"), "/ROOT/content/zimfile/A/"));
ASSERT_TRUE(kiwix::startsWith(g->get_header_value("Location"), "/ROOT/content/zimfile/A%2F"));
ASSERT_EQ(getCacheControlHeader(*g), "max-age=0, must-revalidate");
ASSERT_FALSE(g->has_header("ETag"));
}
@ -1196,13 +1196,24 @@ TEST_F(ServerTest, NonEndpointUrlsAreRedirectedToContentUrls)
}
}
TEST_F(ServerTest, RedirectionsToURLsWithSpecialSymbols)
{
auto g = zfs1_->GET("/ROOT/content/corner_cases/wtf.html");
ASSERT_EQ(302, g->status);
ASSERT_TRUE(g->has_header("Location"));
ASSERT_EQ(g->get_header_value("Location"), "/ROOT/content/corner_cases/wtf%3F.html");
ASSERT_EQ(getCacheControlHeader(*g), "max-age=0, must-revalidate");
ASSERT_FALSE(g->has_header("ETag"));
}
TEST_F(ServerTest, BookMainPageIsRedirectedToArticleIndex)
{
{
auto g = zfs1_->GET("/ROOT/content/zimfile");
ASSERT_EQ(302, g->status);
ASSERT_TRUE(g->has_header("Location"));
ASSERT_EQ("/ROOT/content/zimfile/A/index", g->get_header_value("Location"));
ASSERT_EQ("/ROOT/content/zimfile/A%2Findex", g->get_header_value("Location"));
}
}
@ -1507,7 +1518,7 @@ TEST_F(ServerTest, InvalidAndMultiRangeByteRangeRequestsResultIn416Responses)
TEST_F(ServerTest, ValidByteRangeRequestsOfZeroSizedEntriesResultIn416Responses)
{
const char url[] = "/ROOT/content/corner_cases/-/empty.js";
const char url[] = "/ROOT/content/corner_cases/empty.js";
const char* ranges[] = {
"bytes=0-",