Skip to content
Merged
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
8 changes: 8 additions & 0 deletions inline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,3 +1325,11 @@ func BenchmarkSmartDoubleQuotes(b *testing.B) {
runMarkdown("this should be normal \"quoted\" text.\n", params)
}
}

func TestEntityNullByte(t *testing.T) {
// � should produce U+FFFD per CommonMark spec section 6.2
doTestsInlineParam(t, []string{
"�",
"<p>\uFFFD</p>\n",
}, TestParams{})
}
7 changes: 6 additions & 1 deletion parser/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,12 @@ func entity(p *Parser, data []byte, offset int) (int, ast.Node) {
codepoint, err = strconv.ParseUint(string(ent[2:len(ent)-1]), 10, 64)
}
if err == nil { // only if conversion was valid return here.
return end, newTextNode([]byte(string(rune(codepoint))))
r := rune(codepoint)
// Replace invalid codepoints with U+FFFD per CommonMark spec section 6.2
if r == 0 || (r >= 0xD800 && r <= 0xDFFF) || r > 0x10FFFF {
r = '\uFFFD'
}
return end, newTextNode([]byte(string(r)))
}

return end, newTextNode(ent)
Expand Down