fix(html): unescape stripped html entities
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
9230d3b66c
commit
436bd3716f
2 changed files with 5 additions and 4 deletions
|
|
@ -3,6 +3,7 @@
|
|||
package html
|
||||
|
||||
import (
|
||||
htmlstd "html"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
|
|
@ -48,7 +49,7 @@ func StripTags(html string) string {
|
|||
b.WriteRune(r)
|
||||
seenText = true
|
||||
}
|
||||
return b.String()
|
||||
return htmlstd.UnescapeString(b.String())
|
||||
}
|
||||
|
||||
// pipeline.go: Imprint renders a node tree to HTML, strips tags, tokenises the text,
|
||||
|
|
|
|||
|
|
@ -55,10 +55,10 @@ func TestStripTags_NoTags(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStripTags_Entities(t *testing.T) {
|
||||
got := StripTags(`<script>`)
|
||||
want := "<script>"
|
||||
got := StripTags(`<p>& <script></p>`)
|
||||
want := "& <script>"
|
||||
if got != want {
|
||||
t.Errorf("StripTags should preserve entities, got %q, want %q", got, want)
|
||||
t.Errorf("StripTags should unescape entities, got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue