mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
fix(sanitizer): MathML tags are not fully supported by golang.org/x/net/html
See https://github.com/golang/net/blob/master/html/atom/gen.go and https://github.com/golang/net/blob/master/html/atom/table.go
This commit is contained in:
parent
d1dc369bb2
commit
828a4334db
2 changed files with 20 additions and 2 deletions
|
@ -82,7 +82,7 @@ var (
|
|||
"annotation": {},
|
||||
"annotation-xml": {},
|
||||
"maction": {},
|
||||
"math": {},
|
||||
"math": {"xmlns"},
|
||||
"merror": {},
|
||||
"mfrac": {},
|
||||
"mi": {},
|
||||
|
@ -131,7 +131,15 @@ func Sanitize(baseURL, input string) string {
|
|||
}
|
||||
|
||||
token := tokenizer.Token()
|
||||
tagName := token.DataAtom.String()
|
||||
|
||||
// Note: MathML elements are not fully supported by golang.org/x/net/html.
|
||||
// See https://github.com/golang/net/blob/master/html/atom/gen.go
|
||||
// and https://github.com/golang/net/blob/master/html/atom/table.go
|
||||
tagName := token.Data
|
||||
if tagName == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
switch token.Type {
|
||||
case html.TextToken:
|
||||
if len(blockedStack) > 0 {
|
||||
|
|
|
@ -705,3 +705,13 @@ func TestAttributesAreStripped(t *testing.T) {
|
|||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMathML(t *testing.T) {
|
||||
input := `<math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mn>2</mn></msup></math>`
|
||||
expected := `<math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mn>2</mn></msup></math>`
|
||||
output := Sanitize("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue