mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
fix: regression caused by security hardening causing clickable icons to not work.
This commit is contained in:
3 files changed
+16
-2
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
export default {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
testEnvironment: 'jsdom',
|
||||
roots: ['<rootDir>/src'],
|
||||
testMatch: [
|
||||
'**/__tests__/**/*.ts',
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import stringToHTML from "./stringToHTML";
|
||||
|
||||
describe("stringToHTML", () => {
|
||||
it("preserves inline onclick handlers used by lesson action buttons", () => {
|
||||
const body = stringToHTML(
|
||||
`<div class="day-button clickable" onclick="location.href='../#?page=/courses/123:456'">Go</div>`,
|
||||
);
|
||||
|
||||
const el = body.firstElementChild as HTMLElement | null;
|
||||
expect(el).not.toBeNull();
|
||||
expect(el?.getAttribute("onclick")).toContain("location.href");
|
||||
});
|
||||
});
|
||||
@@ -16,8 +16,9 @@ export default function stringToHTML(str: string, styles = false) {
|
||||
const parser = new DOMParser();
|
||||
|
||||
str = DOMPurify.sanitize(str, {
|
||||
ADD_ATTR: ["onclick"],
|
||||
ALLOWED_URI_REGEXP:
|
||||
/^(?:(?:https?|mailto|tel):|\/|#|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,
|
||||
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|chrome-extension):|\/|#|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,
|
||||
});
|
||||
|
||||
const doc = parser.parseFromString(str, "text/html");
|
||||
|
||||
Reference in new issue
Block a user