|
|
|
@@ -346,6 +346,7 @@ R"EXPECTEDRESULT( <link type="text/css" href="./skin/kiwix.css?cacheid=3948b8
|
|
|
|
|
{
|
|
|
|
|
/* url */ "/ROOT%23%3F/content/invalid-book/whatever",
|
|
|
|
|
R"EXPECTEDRESULT( <link type="text/css" href="/ROOT%23%3F/skin/error.css?cacheid=c49d1586" rel="Stylesheet" />
|
|
|
|
|
window.KIWIX_RESPONSE_TEMPLATE = "<!DOCTYPE html>\n<html>\n <head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />\n <title>{{PAGE_TITLE}}</title>\n <link type="text/css" href="{{root}}/skin/error.css?cacheid=c49d1586" rel="Stylesheet" />\n{{#KIWIX_RESPONSE_DATA}} <script>\n window.KIWIX_RESPONSE_TEMPLATE = "{{KIWIX_RESPONSE_TEMPLATE}}";\n window.KIWIX_RESPONSE_DATA = {{{KIWIX_RESPONSE_DATA}}};\n </script>{{/KIWIX_RESPONSE_DATA}}\n </head>\n <body>\n <header>\n <img src="{{root}}/skin/404.svg?cacheid=b6d648af"\n alt="Not found!"\n aria-label="Not found!"\n title="Not found!">\n </header>\n <section class="intro">\n <h1>{{PAGE_HEADING}}</h1>\n <p>The requested path was not found:</p>\n <p><code>{{url_path}}</code></p>\n </section>\n <section class="advice">\n <p>The content you're looking for may still be available, but it might be located at a different place within the ZIM file.</p>\n <p class="list-intro">Please:</p>\n <ul>\n <li>Try using the search function to find the content you want</li>\n <li>Look for keywords or titles related to the information you're seeking</li>\n </ul>\n <p>This approach should help you locate the desired content, even if the original link isn't working properly.</p>\n </section>\n </body>\n</html>\n";
|
|
|
|
|
<img src="/ROOT%23%3F/skin/404.svg?cacheid=b6d648af"
|
|
|
|
|
)EXPECTEDRESULT"
|
|
|
|
|
},
|
|
|
|
@@ -922,9 +923,17 @@ std::string htmlEscape(std::string s)
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string escapeJsString(std::string s)
|
|
|
|
|
{
|
|
|
|
|
s = replace(s, "</script>", "</scr\\ipt>");
|
|
|
|
|
s = replace(s, "\"", "\\\"");
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string expectedSexy404ErrorHtml(const std::string& url)
|
|
|
|
|
{
|
|
|
|
|
const auto htmlSafeUrl = htmlEscape(url);
|
|
|
|
|
const auto jsSafeUrl = escapeJsString(url);
|
|
|
|
|
|
|
|
|
|
return R"RAWSTRINGLITERAL(<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
@@ -933,6 +942,14 @@ std::string expectedSexy404ErrorHtml(const std::string& url)
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
|
|
|
<title>Page not found</title>
|
|
|
|
|
<link type="text/css" href="/ROOT%23%3F/skin/error.css?cacheid=c49d1586" rel="Stylesheet" />
|
|
|
|
|
<script>
|
|
|
|
|
window.KIWIX_RESPONSE_TEMPLATE = "<!DOCTYPE html>\n<html>\n <head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />\n <title>{{PAGE_TITLE}}</title>\n <link type="text/css" href="{{root}}/skin/error.css?cacheid=c49d1586" rel="Stylesheet" />\n{{#KIWIX_RESPONSE_DATA}} <script>\n window.KIWIX_RESPONSE_TEMPLATE = "{{KIWIX_RESPONSE_TEMPLATE}}";\n window.KIWIX_RESPONSE_DATA = {{{KIWIX_RESPONSE_DATA}}};\n </script>{{/KIWIX_RESPONSE_DATA}}\n </head>\n <body>\n <header>\n <img src="{{root}}/skin/404.svg?cacheid=b6d648af"\n alt="Not found!"\n aria-label="Not found!"\n title="Not found!">\n </header>\n <section class="intro">\n <h1>{{PAGE_HEADING}}</h1>\n <p>The requested path was not found:</p>\n <p><code>{{url_path}}</code></p>\n </section>\n <section class="advice">\n <p>The content you're looking for may still be available, but it might be located at a different place within the ZIM file.</p>\n <p class="list-intro">Please:</p>\n <ul>\n <li>Try using the search function to find the content you want</li>\n <li>Look for keywords or titles related to the information you're seeking</li>\n </ul>\n <p>This approach should help you locate the desired content, even if the original link isn't working properly.</p>\n </section>\n </body>\n</html>\n";
|
|
|
|
|
window.KIWIX_RESPONSE_DATA = { "PAGE_HEADING" : { "msgid" : "new-404-page-heading", "params" : { } }, "PAGE_TITLE" : { "msgid" : "new-404-page-title", "params" : { } }, "root" : "/ROOT%23%3F", "url_path" : ")RAWSTRINGLITERAL"
|
|
|
|
|
+ // inject the URL
|
|
|
|
|
jsSafeUrl // inject the URL
|
|
|
|
|
+ // inject the URL
|
|
|
|
|
R"RAWSTRINGLITERAL(" };
|
|
|
|
|
</script>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<header>
|
|
|
|
@@ -1458,37 +1475,37 @@ TEST_F(ServerTest, UserLanguageControl)
|
|
|
|
|
"Default user language is English",
|
|
|
|
|
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
|
|
|
|
|
/*Accept-Language:*/ "",
|
|
|
|
|
/* expected <h1> */ "Not Found"
|
|
|
|
|
/* expected <h1> */ "Oops. Page not found."
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"userlang URL query parameter is respected",
|
|
|
|
|
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=en",
|
|
|
|
|
/*Accept-Language:*/ "",
|
|
|
|
|
/* expected <h1> */ "Not Found"
|
|
|
|
|
/* expected <h1> */ "Oops. Page not found."
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"userlang URL query parameter is respected",
|
|
|
|
|
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=test",
|
|
|
|
|
/*Accept-Language:*/ "",
|
|
|
|
|
/* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive"
|
|
|
|
|
/* expected <h1> */ "[I18N TESTING] Oops. Larry Page could not be reached. He may be on paternity leave."
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"'Accept-Language: *' is handled",
|
|
|
|
|
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
|
|
|
|
|
/*Accept-Language:*/ "*",
|
|
|
|
|
/* expected <h1> */ "Not Found"
|
|
|
|
|
/* expected <h1> */ "Oops. Page not found."
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"Accept-Language: header is respected",
|
|
|
|
|
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
|
|
|
|
|
/*Accept-Language:*/ "test",
|
|
|
|
|
/* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive"
|
|
|
|
|
/* expected <h1> */ "[I18N TESTING] Oops. Larry Page could not be reached. He may be on paternity leave."
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"userlang query parameter takes precedence over Accept-Language",
|
|
|
|
|
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=en",
|
|
|
|
|
/*Accept-Language:*/ "test",
|
|
|
|
|
/* expected <h1> */ "Not Found"
|
|
|
|
|
/* expected <h1> */ "Oops. Page not found."
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"Most suitable language is selected from the Accept-Language header",
|
|
|
|
@@ -1496,7 +1513,7 @@ TEST_F(ServerTest, UserLanguageControl)
|
|
|
|
|
// with quality values) the most suitable language is selected.
|
|
|
|
|
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
|
|
|
|
|
/*Accept-Language:*/ "test;q=0.9, en;q=0.2",
|
|
|
|
|
/* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive"
|
|
|
|
|
/* expected <h1> */ "[I18N TESTING] Oops. Larry Page could not be reached. He may be on paternity leave."
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"Most suitable language is selected from the Accept-Language header",
|
|
|
|
@@ -1504,7 +1521,7 @@ TEST_F(ServerTest, UserLanguageControl)
|
|
|
|
|
// with quality values) the most suitable language is selected.
|
|
|
|
|
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
|
|
|
|
|
/*Accept-Language:*/ "test;q=0.2, en;q=0.9",
|
|
|
|
|
/* expected <h1> */ "Not Found"
|
|
|
|
|
/* expected <h1> */ "Oops. Page not found."
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|