diff --git a/static/skin/viewer.js b/static/skin/viewer.js
index 9571b1ee..24050a3b 100644
--- a/static/skin/viewer.js
+++ b/static/skin/viewer.js
@@ -346,13 +346,19 @@ function setupSuggestions() {
},
resultItem: {
element: (item, data) => {
- let searchLink;
+ const uriEncodedBookName = encodeURIComponent(currentBook);
+ let url;
if (data.value.kind == "path") {
- searchLink = `/${currentBook}/${htmlDecode(data.value.path)}`;
+ const path = encodeURIComponent(htmlDecode(data.value.path));
+ url = `/${uriEncodedBookName}/${path}`;
} else {
- searchLink = `/search?content=${encodeURIComponent(currentBook)}&pattern=${encodeURIComponent(htmlDecode(data.value.value))}`;
+ const pattern = encodeURIComponent(htmlDecode(data.value.value));
+ url = `/search?content=${uriEncodedBookName}&pattern=${pattern}`;
}
- const jsAction = `gotoUrl('${searchLink}')`;
+ // url can't contain any double quote and/or backslash symbols
+ // since they should have been URI-encoded. Therefore putting it
+ // inside double quotes should result in valid javascript.
+ const jsAction = `gotoUrl("${url}")`;
const linkText = htmlDecode(data.value.label);
item.innerHTML = makeJSLink(jsAction, linkText, 'class="suggest"');
},
diff --git a/test/server.cpp b/test/server.cpp
index a166fa0a..9b2da29a 100644
--- a/test/server.cpp
+++ b/test/server.cpp
@@ -69,7 +69,7 @@ const ResourceCollection resources200Compressible{
{ DYNAMIC_CONTENT, "/ROOT/skin/taskbar.css" },
{ STATIC_CONTENT, "/ROOT/skin/taskbar.css?cacheid=216d6b5d" },
{ DYNAMIC_CONTENT, "/ROOT/skin/viewer.js" },
- { STATIC_CONTENT, "/ROOT/skin/viewer.js?cacheid=e250a5c9" },
+ { STATIC_CONTENT, "/ROOT/skin/viewer.js?cacheid=23966598" },
{ DYNAMIC_CONTENT, "/ROOT/skin/fonts/Poppins.ttf" },
{ STATIC_CONTENT, "/ROOT/skin/fonts/Poppins.ttf?cacheid=af705837" },
{ DYNAMIC_CONTENT, "/ROOT/skin/fonts/Roboto.ttf" },
@@ -291,7 +291,7 @@ R"EXPECTEDRESULT(
-
+
const blankPageUrl = root + "/skin/blank.html?cacheid=6b1fa032";