// give a generous extra 50 bytes
res := make([]byte, 0, len(rawHTML)+50)
+
+ // prepend "<html><body>"
res = append(res, "<html><body>"...)
- res = append(res, rawHTML...)
+
+ // Strip out nuls - they're always invalid
+ start := bytes.IndexByte(rawHTML, '\000')
+ if start >= 0 {
+ res = append(res, rawHTML[:start]...)
+ start++
+ for start < len(rawHTML) {
+ end := bytes.IndexByte(rawHTML[start:], '\000')
+ if end < 0 {
+ res = append(res, rawHTML[start:]...)
+ break
+ } else if end > 0 {
+ res = append(res, rawHTML[start:start+end]...)
+ }
+ start += end + 1
+ }
+ } else {
+ res = append(res, rawHTML...)
+ }
+
+ // close the tags
res = append(res, "</body></html>"...)
// parse the HTML