internal/godoc: do not unescape HTML
The HTML does not need to unescaped when parsing, which is now fixed.
An error in escaping the test HTML input is also fixed.
Change-Id: I1cd98228255d202b9579e80f4ef4269dc593c42b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/257718
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/godoc/parse.go b/internal/godoc/parse.go
index d2e4f04..4e64b02 100644
--- a/internal/godoc/parse.go
+++ b/internal/godoc/parse.go
@@ -10,7 +10,6 @@
import (
"fmt"
- "html"
"regexp"
"github.com/google/safehtml"
@@ -70,6 +69,6 @@
// sidenav sections. For the body, this will capture all content up the
// last </div> tag in the HTML.
reg := fmt.Sprintf("(%s(.|\n)*%s)", identifier, closeTag)
- b := regexp.MustCompile(reg).FindString(html.UnescapeString(docHTML.String()))
- return uncheckedconversions.HTMLFromStringKnownToSatisfyTypeContract(string(b)), nil
+ s := regexp.MustCompile(reg).FindString(docHTML.String())
+ return uncheckedconversions.HTMLFromStringKnownToSatisfyTypeContract(s), nil
}
diff --git a/internal/godoc/parse_test.go b/internal/godoc/parse_test.go
index 8ddfab2..8c2b984 100644
--- a/internal/godoc/parse_test.go
+++ b/internal/godoc/parse_test.go
@@ -8,7 +8,7 @@
"testing"
"github.com/google/go-cmp/cmp"
- "github.com/google/safehtml"
+ "github.com/google/safehtml/uncheckedconversions"
)
func TestParse(t *testing.T) {
@@ -34,7 +34,7 @@
} {
{
t.Run(test.name, func(t *testing.T) {
- got, err := Parse(safehtml.HTMLEscaped(quoteDocHTML), test.section)
+ got, err := Parse(uncheckedconversions.HTMLFromStringKnownToSatisfyTypeContract(quoteDocHTML), test.section)
if err != nil {
t.Fatal(err)
}