-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from M4tteoP/fix_isBlackAttr
fix: attr with multiple nulls
- Loading branch information
Showing
2 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package libinjection | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestIsBlackAttr(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
attr string | ||
want int | ||
}{ | ||
{ | ||
name: "Test with black attribute", | ||
attr: "xmlns", | ||
want: attributeTypeBlack, | ||
}, | ||
{ | ||
name: "Test with non-black attribute", | ||
attr: "class", | ||
want: attributeTypeNone, | ||
}, | ||
{ | ||
name: "Test with JavaScript event handler", | ||
attr: "onclick", | ||
want: attributeTypeBlack, | ||
}, | ||
{ | ||
name: "Test with short attribute", | ||
attr: "a", | ||
want: attributeTypeNone, | ||
}, | ||
{ | ||
name: "Test with long null attribute that will be stripped", | ||
attr: "a\x00\x00\x00\x00\x00", | ||
want: attributeTypeNone, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := isBlackAttr(tt.attr); got != tt.want { | ||
t.Errorf("isBlackAttr() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |