p2: widen document fence for space and zero-width
Strip U+200B–U+200D, U+2060, U+FEFF before fencing. Match (?i)<\s*/?\s*document so </ document> cannot sit outside the frame.
This commit is contained in:
@@ -577,11 +577,15 @@ func min(a, b int) int {
|
||||
return b
|
||||
}
|
||||
|
||||
var documentTag = regexp.MustCompile(`(?i)</?document`)
|
||||
var (
|
||||
documentTag = regexp.MustCompile(`(?i)<\s*/?\s*document`)
|
||||
zwChars = regexp.MustCompile("[\u200b\u200c\u200d\u2060\ufeff]")
|
||||
)
|
||||
|
||||
func fenceDocument(s string) string {
|
||||
s = zwChars.ReplaceAllString(s, "")
|
||||
return documentTag.ReplaceAllStringFunc(s, func(m string) string {
|
||||
if len(m) >= 2 && m[1] == '/' {
|
||||
if strings.Contains(m, "/") {
|
||||
return "</document"
|
||||
}
|
||||
return "<document"
|
||||
|
||||
Reference in New Issue
Block a user