From 27bf63ad20e3241d48636064f585a6d432bdcaa7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 3 Mar 2025 10:57:28 +0800 Subject: Refactor global init code and add more comments (#33755) Follow up #33748 Now there are 3 "global" functions: * registerGlobalSelectorFunc: for all elements matching the selector, eg: `.ui.dropdown` * registerGlobalInitFunc: for `data-global-init="initInputAutoFocusEnd"` * registerGlobalEventFunc: for `data-global-click="onCommentReactionButtonClick"` And introduce `initGlobalInput` to replace old `initAutoFocusEnd` and `attachDirAuto`, use `data-global-init` to replace fragile `.js-autofocus-end` selector. Another benefit is that by the new approach, no matter how many times `registerGlobalInitFunc` is called, we only need to do one "querySelectorAll" in the last step, it could slightly improve the performance. --- modules/markup/sanitizer_default_test.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules') diff --git a/modules/markup/sanitizer_default_test.go b/modules/markup/sanitizer_default_test.go index e6fbae5056..5282916944 100644 --- a/modules/markup/sanitizer_default_test.go +++ b/modules/markup/sanitizer_default_test.go @@ -62,6 +62,10 @@ func TestSanitizer(t *testing.T) { `bad`, `bad`, `bad`, `bad`, `bad`, `bad`, + + // Some classes and attributes are used by the frontend framework and will execute JS code, so make sure they are removed + ``, `
txt
`, + `
txt
`, `
txt
`, } for i := 0; i < len(testCases); i += 2 { -- cgit v1.2.3