Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing HTML attributes with _ as the first character in the name (#355) #356

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,11 @@ static boolean isValidHtmlName(String name) {
if (i == 0 || i + 1 == n) { return false; }
break;
case '-':
case '_':
if (i == 0 || i + 1 == n) { return false; }
break;
case '_':
if (i + 1 == n) { return false; }
break;
default:
if (ch <= '9') {
if (i == 0 || ch < '0') { return false; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public static final void testEmptyAndValuelessAttributes() {
sanitize("<input checked type=checkbox id=\"\" class=>"));
}

@Test
public final void testAllowedAttributes() {
assertEquals(
"<div __foo=\"__foo\" __bar=\"foo\" foo-bar=\"foo-bar\"></div>",
sanitize("<div __foo __bar=\"foo\" foo-bar></div>"));
}

@Test
public static final void testSgmlShortTags() {
// We make no attempt to correctly handle SGML short tags since they are
Expand Down Expand Up @@ -471,7 +478,8 @@ public void handle(String errorMessage) {
"ol", "p", "span", "ul", "noscript", "noframes", "noembed", "noxss")
// And these attributes.
.allowAttributes(
"dir", "checked", "class", "href", "id", "target", "title", "type")
"dir", "checked", "class", "href", "id", "target", "title", "type",
"__foo", "__bar", "foo-bar")
.globally()
// Cleanup IDs and CLASSes and prefix them with p- to move to a separate
// name-space.
Expand Down