Skip to content

Commit

Permalink
Remove duplicate vals
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiz committed Dec 30, 2021
1 parent 1eebb57 commit 6e7247e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,13 @@ attrsLoop:
if htmlAttr.Key == "sandbox" {
sandboxFound = true
var cleanVals []string
cleanValsSet := make(map[string]bool)
for _, val := range strings.Fields(htmlAttr.Val) {
if p.requireSandboxOnIFrame[val] {
cleanVals = append(cleanVals, val)
if !cleanValsSet[val] {
cleanVals = append(cleanVals, val)
cleanValsSet[val] = true
}
}
}
cleanAttrs[i].Val = strings.Join(cleanVals, " ")
Expand Down
2 changes: 1 addition & 1 deletion sanitize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ func TestIFrameSandbox(t *testing.T) {
p.AllowAttrs("sandbox").OnElements("iframe")
p.RequireSandboxOnIFrame(SandboxAllowDownloads)

in := `<iframe src="http://example.com" sandbox="allow-forms allow-downloads"></iframe>`
in := `<iframe src="http://example.com" sandbox="allow-forms allow-downloads allow-downloads"></iframe>`
expected := `<iframe sandbox="allow-downloads"></iframe>`
out := p.Sanitize(in)
if out != expected {
Expand Down

0 comments on commit 6e7247e

Please sign in to comment.