Skip to content

Commit

Permalink
Don't replace & => & when followed by character that could be an …
Browse files Browse the repository at this point in the history
…entity (some browsers allow entities without closing semicolon)
  • Loading branch information
tdewolff committed Dec 12, 2022
1 parent f2e7ed0 commit 9190118
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 1 addition & 6 deletions util.go
Expand Up @@ -280,12 +280,7 @@ func replaceEntities(b []byte, i int, entitiesMap map[string][]byte, revEntities
} else if r[0] == '&' {
// check if for example & is followed by something that could potentially be an entity
k := j + 1
if k < len(b) && b[k] == '#' {
k++
}
for ; k < len(b) && k-j <= MaxEntityLength && (b[k] >= '0' && b[k] <= '9' || b[k] >= 'a' && b[k] <= 'z' || b[k] >= 'A' && b[k] <= 'Z'); k++ {
}
if k < len(b) && b[k] == ';' {
if k < len(b) && (b[k] >= '0' && b[k] <= '9' || b[k] >= 'a' && b[k] <= 'z' || b[k] >= 'A' && b[k] <= 'Z' || b[k] == '#') {
return b, k
}
}
Expand Down
5 changes: 3 additions & 2 deletions util_test.go
Expand Up @@ -136,10 +136,11 @@ func TestReplaceEntities(t *testing.T) {
{"&#39;", `&#39;`},
{"&amp;amp;", `&amp;amp;`},
{"&amp;#34;", `&amp;#34;`},
{"&amp;a mp;", `&a mp;`},
//{"&amp;a mp;", `&a mp;`},
{"&amp;DiacriticalAcute;", `&amp;DiacriticalAcute;`},
{"&amp;CounterClockwiseContourIntegral;", `&amp;CounterClockwiseContourIntegral;`},
{"&amp;CounterClockwiseContourIntegralL;", `&CounterClockwiseContourIntegralL;`},
//{"&amp;CounterClockwiseContourIntegralL;", `&CounterClockwiseContourIntegralL;`},
{"&amp;parameterize", `&amp;parameterize`},
{"&varphi;", "&phiv;"},
{"&varpi;", "&piv;"},
{"&varnone;", "&varnone;"},
Expand Down

0 comments on commit 9190118

Please sign in to comment.