Skip to content

Commit d8287d0

Browse files
author
Chad Norvell
committed
rustdoc: Enforce theme actually exists
1 parent 4f63e4c commit d8287d0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/librustdoc/html/static/js/storage.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ const getVar = (function getVar(name) {
109109
});
110110

111111
function switchTheme(newThemeName, saveTheme) {
112+
const theme_names = getVar("themes").split(",").filter(t => t);
113+
theme_names.push("light", "dark", "ayu");
114+
115+
if (theme_names.indexOf(newThemeName) == -1) {
116+
return;
117+
}
118+
112119
// If this new value comes from a system setting or from the previously
113120
// saved theme, no need to save it.
114121
if (saveTheme) {
@@ -123,7 +130,7 @@ function switchTheme(newThemeName, saveTheme) {
123130
window.currentTheme = null;
124131
}
125132
} else {
126-
const newHref = getVar("root-path") + newThemeName +
133+
const newHref = getVar("root-path") + encodeURIComponent(newThemeName) +
127134
getVar("resource-suffix") + ".css";
128135
if (!window.currentTheme) {
129136
// If we're in the middle of loading, document.write blocks

0 commit comments

Comments
 (0)