Skip to content

Commit

Permalink
rustdoc: Enforce theme actually exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Norvell committed Jan 24, 2024
1 parent 4f63e4c commit d8287d0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ const getVar = (function getVar(name) {
});

function switchTheme(newThemeName, saveTheme) {
const theme_names = getVar("themes").split(",").filter(t => t);
theme_names.push("light", "dark", "ayu");

if (theme_names.indexOf(newThemeName) == -1) {
return;
}

// If this new value comes from a system setting or from the previously
// saved theme, no need to save it.
if (saveTheme) {
Expand All @@ -123,7 +130,7 @@ function switchTheme(newThemeName, saveTheme) {
window.currentTheme = null;
}
} else {
const newHref = getVar("root-path") + newThemeName +
const newHref = getVar("root-path") + encodeURIComponent(newThemeName) +
getVar("resource-suffix") + ".css";
if (!window.currentTheme) {
// If we're in the middle of loading, document.write blocks
Expand Down

0 comments on commit d8287d0

Please sign in to comment.