URI-encoding of redirections to URLs with special symbols

This commit is contained in:
Veloman Yunkan 2023-01-07 15:45:33 +04:00
parent 78b2c1a273
commit 8eb527389e
2 changed files with 4 additions and 4 deletions

View File

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

View File

@ -1145,7 +1145,7 @@ TEST_F(ServerTest, RandomPageRedirectsToAnExistingArticle)
auto g = zfs1_->GET("/ROOT/random?content=zimfile"); auto g = zfs1_->GET("/ROOT/random?content=zimfile");
ASSERT_EQ(302, g->status); ASSERT_EQ(302, g->status);
ASSERT_TRUE(g->has_header("Location")); 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_EQ(getCacheControlHeader(*g), "max-age=0, must-revalidate");
ASSERT_FALSE(g->has_header("ETag")); ASSERT_FALSE(g->has_header("ETag"));
} }
@ -1201,7 +1201,7 @@ TEST_F(ServerTest, RedirectionsToURLsWithSpecialSymbols)
auto g = zfs1_->GET("/ROOT/content/corner_cases/wtf.html"); auto g = zfs1_->GET("/ROOT/content/corner_cases/wtf.html");
ASSERT_EQ(302, g->status); ASSERT_EQ(302, g->status);
ASSERT_TRUE(g->has_header("Location")); ASSERT_TRUE(g->has_header("Location"));
ASSERT_EQ(g->get_header_value("Location"), "/ROOT/content/corner_cases/wtf?.html"); ASSERT_EQ(g->get_header_value("Location"), "/ROOT/content/corner_cases/wtf%3F.html");
ASSERT_EQ(getCacheControlHeader(*g), "max-age=0, must-revalidate"); ASSERT_EQ(getCacheControlHeader(*g), "max-age=0, must-revalidate");
ASSERT_FALSE(g->has_header("ETag")); ASSERT_FALSE(g->has_header("ETag"));
} }
@ -1213,7 +1213,7 @@ TEST_F(ServerTest, BookMainPageIsRedirectedToArticleIndex)
auto g = zfs1_->GET("/ROOT/content/zimfile"); auto g = zfs1_->GET("/ROOT/content/zimfile");
ASSERT_EQ(302, g->status); ASSERT_EQ(302, g->status);
ASSERT_TRUE(g->has_header("Location")); 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"));
} }
} }