Skip to content

WIP: Allow all characters in title attribute when rendering #10371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/markup/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func TestRender_Images(t *testing.T) {
test(
"[!["+title+"]("+url+")]("+href+")",
`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
test(
"!["+title+"]("+url+" \"1 -> 2 -> 3 -> 4 -> 5\")",
`<p><a href="`+result+`" title="1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
test(
"!["+title+"]("+url+" \"this?is#a!test:P\")",
`<p><a href="`+result+`" title="this?is#a!test:P" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
}

func testAnswers(baseURLContent, baseURLImages string) []string {
Expand Down
3 changes: 3 additions & 0 deletions modules/markup/sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func ReplaceSanitizer() {
// Allow classes for anchors
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue`)).OnElements("a")

// Allow more characters in title attribute per commonmark spec
sanitizer.policy.AllowAttrs("title").Matching(regexp.MustCompile(`(.*?)`)).OnElements("a")

// Custom keyword markup
for _, rule := range setting.ExternalSanitizerRules {
if rule.Regexp != nil {
Expand Down