Skip to content

Commit

Permalink
Support ARIA role property
Browse files Browse the repository at this point in the history
  • Loading branch information
torusrxxx committed Dec 6, 2024
1 parent bf3833e commit e470b94
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/freenet/client/filter/HTMLFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.charset.MalformedInputException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -2111,6 +2112,7 @@ static class TagVerifier {
private final HashSet<String> uriAttrs;
private final HashSet<String> inlineURIAttrs;
final HashSet<String> booleanAttrs;
private final HashSet<String> allowedRole;

TagVerifier(String tag, String[] allowedAttrs) {
this(tag, allowedAttrs, null, null, null);
Expand Down Expand Up @@ -2140,6 +2142,25 @@ static class TagVerifier {
this.booleanAttrs.add(booleanAttrs[x]);
}
}
// https://w3c.github.io/aria/
this.allowedRole = new HashSet<String>(Arrays.asList("alert","alertdialog","application","article",
"banner","blockquote","button",
"caption","cell","checkbox","code","columnheader","combobox","command","comment","complementary","composite","contentinfo",
"definition","deletion","dialog","directory","document",
"emphasis",
"feed","figure","form",
"generic","grid","gridcell","group",
"heading",
"image","img","input","insertion",
"landmark","link","list","listbox","listitem","log",
"main","mark","marquee","math","menu","menubar","menuitem","menuitemcheckbox","menuitemradio","meter",
"navigation","none","note",
"option",
"paragraph","presentation","progressbar",
"radio","radiogroup","range","region","roletype","row","rowgroup","rowheader",
"scrollbar","search","searchbox","section","sectionhead","select","separator","slider","spinbutton","status","strong","structure","subscript","suggestion","superscript","switch",
"tab","table","tablist","tabpanel","term","textbox","time","timer","toolbar","tooltip","tree","treegrid","treeitem",
"widget","window"));
}

ParsedTag sanitize(ParsedTag t, HTMLParseContext pc) throws DataFilterException {
Expand Down Expand Up @@ -2286,6 +2307,13 @@ Map<String, Object> sanitizeHash(Map<String, Object> h,
if(logDEBUG) Logger.debug(this, "HTML Filter is putting attribute: "+x+" = "+o);
hn.put(x, o);
}
// ARIA properties
// role can be set on any element
if (x.equals("role") && o instanceof String) {
if(allowedRole.contains((String)o)) {
hn.put(x, o);
}
}
}
return hn;
}
Expand Down
7 changes: 7 additions & 0 deletions test/freenet/client/filter/ContentFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,11 @@ public void testLowerCaseExtensions() {
}
}
}

private static final String ARIA_ROLE_TEST = "<span role=\"caption\" />";

@Test
public void testARIAProperties() throws Exception {
assertEquals(ARIA_ROLE_TEST, htmlFilter(ARIA_ROLE_TEST));
}
}

0 comments on commit e470b94

Please sign in to comment.