Skip to content

Commit

Permalink
rustdoc: Remove regex sanitation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Norvell committed Jan 24, 2024
1 parent d8287d0 commit e4c0401
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@ function getSettingValue(settingName) {
return def;
}
}
// Strip out characters we don't expect to find in settings values.
// This prevents an injection vulnerability where someone could plant
// JS code into the localStorage value, which could be executed when
// we pull it out.
if (current) {
return current.replace(/[\s()[\]{}*"'`<>.:;=&|]/g,"");
}

return null;
return current;
}

const localStoredTheme = getSettingValue("theme");
Expand Down Expand Up @@ -109,10 +101,11 @@ const getVar = (function getVar(name) {
});

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

if (theme_names.indexOf(newThemeName) == -1) {
// Ensure that the new theme name is among the defined themes
if (themeNames.indexOf(newThemeName) === -1) {
return;
}

Expand Down

0 comments on commit e4c0401

Please sign in to comment.