Skip to content

Commit ce66ca7

Browse files
authored
Restore checkbox rendering and prevent poor sanitization of spans (#11277)
* Add test Signed-off-by: Andrew Thornton <[email protected]> * Restore checkbox rendering and prevent poor sanitization of spans Signed-off-by: Andrew Thornton <[email protected]> * Also fix preview context Signed-off-by: Andrew Thornton <[email protected]> * Also fix preview context Signed-off-by: Andrew Thornton <[email protected]>
1 parent 940ed92 commit ce66ca7

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

modules/markup/markdown/markdown_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
140140
</ol>
141141
<h2 id="user-content-custom-id">More tests</h2>
142142
<p>(from <a href="https://www.markdownguide.org/extended-syntax/" rel="nofollow">https://www.markdownguide.org/extended-syntax/</a>)</p>
143+
<h3 id="user-content-checkboxes">Checkboxes</h3>
144+
<ul class="task-list">
145+
<li><span class="ui checkbox"><input type="checkbox" readonly="readonly"/><label>unchecked</label></span></li>
146+
<li><span class="ui checked checkbox"><input type="checkbox" checked="" readonly="readonly"/><label>checked</label></span></li>
147+
<li><span class="ui checkbox"><input type="checkbox" readonly="readonly"/><label>still unchecked</label></span></li>
148+
</ul>
143149
<h3 id="user-content-definition-list">Definition list</h3>
144150
<dl>
145151
<dt>First Term</dt>
@@ -207,6 +213,12 @@ Here are some links to the most important topics. You can find the full list of
207213
208214
(from https://www.markdownguide.org/extended-syntax/)
209215
216+
### Checkboxes
217+
218+
- [ ] unchecked
219+
- [x] checked
220+
- [ ] still unchecked
221+
210222
### Definition list
211223
212224
First Term

modules/markup/sanitizer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,16 @@ func ReplaceSanitizer() {
5858

5959
// Allow icons
6060
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`^icon(\s+[\p{L}\p{N}_-]+)+$`)).OnElements("i")
61-
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(ui checkbox)|(ui checked checkbox))$`)).OnElements("span")
6261

6362
// Allow unlabelled labels
6463
sanitizer.policy.AllowNoAttrs().OnElements("label")
6564

6665
// Allow classes for emojis
67-
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`emoji`)).OnElements("span")
6866
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`emoji`)).OnElements("img")
6967

68+
// Allow icons, checkboxes and emojis on span
69+
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(ui checkbox)|(ui checked checkbox)|(emoji))$`)).OnElements("span")
70+
7071
// Allow generally safe attributes
7172
generalSafeAttrs := []string{"abbr", "accept", "accept-charset",
7273
"accesskey", "action", "align", "alt",

modules/markup/sanitizer_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ func Test_Sanitizer(t *testing.T) {
3838

3939
// <kbd> tags
4040
`<kbd>Ctrl + C</kbd>`, `<kbd>Ctrl + C</kbd>`,
41+
`<i class="dropdown icon">NAUGHTY</i>`, `<i>NAUGHTY</i>`,
42+
`<i class="icon dropdown"></i>`, `<i class="icon dropdown"></i>`,
43+
`<span class="ui checkbox"><input type="checkbox" readonly="readonly"/><label>unchecked</label></span>`, `<span class="ui checkbox"><input type="checkbox" readonly="readonly"/><label>unchecked</label></span>`,
44+
`<span class="emoji dropdown">NAUGHTY</span>`, `<span>NAUGHTY</span>`,
45+
`<span class="emoji">contents</span>`, `<span class="emoji">contents</span>`,
4146
}
4247

4348
for i := 0; i < len(testCases); i += 2 {

web_src/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function initEditPreviewTab($form) {
6565
previewFileModes = $previewTab.data('preview-file-modes').split(',');
6666
$previewTab.on('click', function () {
6767
const $this = $(this);
68-
let context = `{$this.data('context')}/`;
68+
let context = `${$this.data('context')}/`;
6969
const treePathEl = $form.find('input#tree_path');
7070
if (treePathEl.length > 0) {
7171
context += treePathEl.val();

0 commit comments

Comments
 (0)