@asymmetric-effort/specifyjs 0.3.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3755,6 +3755,12 @@ var BUTTON_META = {
|
|
|
3755
3755
|
undo: { label: "Undo", icon: "\u21A9", command: "undo" },
|
|
3756
3756
|
redo: { label: "Redo", icon: "\u21AA", command: "redo" }
|
|
3757
3757
|
};
|
|
3758
|
+
var STRIP_SCRIPTS = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
|
|
3759
|
+
var STRIP_EVENTS_QUOTED = /\s+on\w+\s*=\s*(['"])[^'"]*\1/gi;
|
|
3760
|
+
var STRIP_EVENTS_UNQUOTED = /\s+on\w+\s*=\s*[^\s>]+/gi;
|
|
3761
|
+
function sanitizeRichText(html) {
|
|
3762
|
+
return html.replace(STRIP_SCRIPTS, "").replace(STRIP_EVENTS_QUOTED, "").replace(STRIP_EVENTS_UNQUOTED, "");
|
|
3763
|
+
}
|
|
3758
3764
|
function TextEditor(props) {
|
|
3759
3765
|
const [focused, setFocused] = useState(false);
|
|
3760
3766
|
const editorRef = useRef(null);
|
|
@@ -3765,7 +3771,7 @@ function TextEditor(props) {
|
|
|
3765
3771
|
const es = props.editorStyle ?? {};
|
|
3766
3772
|
useEffect(() => {
|
|
3767
3773
|
if (editorRef.current && props.value !== void 0) {
|
|
3768
|
-
editorRef.current.innerHTML = props.value;
|
|
3774
|
+
editorRef.current.innerHTML = sanitizeRichText(props.value);
|
|
3769
3775
|
}
|
|
3770
3776
|
}, []);
|
|
3771
3777
|
const execCommand = useCallback(
|
|
@@ -3774,6 +3780,7 @@ function TextEditor(props) {
|
|
|
3774
3780
|
if (cmd === "createLink") {
|
|
3775
3781
|
const url = prompt("Enter URL:");
|
|
3776
3782
|
if (!url) return;
|
|
3783
|
+
if (/^(javascript|vbscript|data:text\/html)/i.test(url.trim())) return;
|
|
3777
3784
|
document.execCommand(cmd, false, url);
|
|
3778
3785
|
} else if (value && cmd === "formatBlock") {
|
|
3779
3786
|
document.execCommand(cmd, false, `<${value}>`);
|