Skip to content

Commit

Permalink
Add elements figcaption,figure,mark,rp,rt,ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
torusrxxx committed Oct 19, 2024
1 parent 8584c21 commit 2b02949
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 50 deletions.
78 changes: 42 additions & 36 deletions src/freenet/client/filter/HTMLFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -953,51 +953,57 @@ private static Map<String, TagVerifier> getAllowedTagVerifiers()
emptyStringArray));
String[] group2 =
{
"span",
"address",
"em",
"strong",
"dfn",
"code",
"samp",
"kbd",
"var",
"cite",
"abbr",
"acronym",
"sub",
"sup",
"dt",
"dd",
"tt",
"i",
"address",
"article",
"aside",
"b",
"big",
"small",
"strike",
"s",
"u",
"noframes",
"fieldset",
// Delete <noscript> / </noscript>. So we can at least see the non-scripting code.
// "noscript",
"xmp",
"listing",
"plaintext",
"center",
"bdi",
"bdo",
"aside",
"big",
"center",
"cite",
"code",
"dd",
"details",
"dfn",
"dt",
"em",
"fieldset",
"figcaption",
"figure",
"footer",
"header",
"hgroup",
"i",
"kbd",
"listing",
"main",
"mark",
"nav",
"footer",
"article",
"noframes",
// Delete <noscript> / </noscript>. So we can at least see the non-scripting code.
//"noscript",
"plaintext",
"rp",
"rt",
"ruby",
"s",
"samp",
"section",
"hgroup",
"wbr",
"small",
"span",
"strike",
"strong",
"sub",
"summary",
"details",
"main"};
"sup",
"tt",
"u",
"var",
"wbr",
"xmp"};
for (String x: group2)
allowedTagsVerifiers.put(
x,
Expand Down
34 changes: 20 additions & 14 deletions test/freenet/client/filter/ContentFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public class ContentFilterTest {

private static final String SPAN_WITH_STYLE = "<span style=\"font-family: verdana, sans-serif; color: red;\">";

private static final String HTML5_TAGS = "<article><details><summary>TLDR</summary><center>Too Long Di<wbr />dn’t Read</center></details></article>";
private static final String HTML5_TAGS = "<main><article><details><summary><mark>TLDR</mark></summary><center>Too Long Di<wbr />dn&rsquo;t Read</center></details><section><figure><figcaption>Fig.1</figcaption></figure></article></main>";
private static final String HTML5_BDI_RUBY = "<small dir=\"auto\"><bdi>&#x0627;&#x06CC;&#x0631;&#x0627;&#x0646;</bdi>, <bdo><ruby>&#xBD81;<rt>North</rt>&#xD55C;<rt>Korea</rt></ruby><rp>North Korea</rp></ruby></bdo></small>";

private static final String BASE_HREF = "<base href=\"/"+BASE_KEY+"\">";
private static final String BAD_BASE_HREF = "<base href=\"/\">";
Expand All @@ -138,6 +139,10 @@ public class ContentFilterTest {
HTML_VIDEO_TAG + HTML_AUDIO_TAG,
HTML_AUDIO_TAG + HTML_AUDIO_TAG);

private static void testOneHTMLFilter(String html) throws Exception {
assertEquals(html, htmlFilter(html));
}

@Test
public void testHTMLFilter() throws Exception {
if (TestProperty.VERBOSE) {
Expand All @@ -146,7 +151,7 @@ public void testHTMLFilter() throws Exception {

// General sanity checks
// is "relativization" working?
assertEquals(INTERNAL_RELATIVE_LINK, htmlFilter(INTERNAL_RELATIVE_LINK));
testOneHTMLFilter(INTERNAL_RELATIVE_LINK);
assertEquals(INTERNAL_RELATIVE_LINK, htmlFilter(INTERNAL_RELATIVE_LINK, true));
assertEquals(INTERNAL_RELATIVE_LINK1, htmlFilter(INTERNAL_RELATIVE_LINK1, true));
assertEquals(INTERNAL_RELATIVE_LINK, htmlFilter(INTERNAL_ABSOLUTE_LINK));
Expand All @@ -157,15 +162,15 @@ public void testHTMLFilter() throws Exception {

// regression testing
// bug #710
assertEquals(ANCHOR_TEST, htmlFilter(ANCHOR_TEST));
assertEquals(ANCHOR_TEST_EMPTY, htmlFilter(ANCHOR_TEST_EMPTY));
assertEquals(ANCHOR_TEST_SPECIAL, htmlFilter(ANCHOR_TEST_SPECIAL));
testOneHTMLFilter(ANCHOR_TEST);
testOneHTMLFilter(ANCHOR_TEST_EMPTY);
testOneHTMLFilter(ANCHOR_TEST_SPECIAL);
assertEquals(ANCHOR_TEST_SPECIAL2_RESULT, htmlFilter(ANCHOR_TEST_SPECIAL2));
// bug #2496
assertEquals(ANCHOR_RELATIVE1, htmlFilter(ANCHOR_RELATIVE1));
assertEquals(ANCHOR_RELATIVE2, htmlFilter(ANCHOR_RELATIVE2));
assertEquals(ANCHOR_FALSE_POS1, htmlFilter(ANCHOR_FALSE_POS1));
assertEquals(ANCHOR_FALSE_POS2, htmlFilter(ANCHOR_FALSE_POS2));
testOneHTMLFilter(ANCHOR_RELATIVE1);
testOneHTMLFilter(ANCHOR_RELATIVE2);
testOneHTMLFilter(ANCHOR_FALSE_POS1);
testOneHTMLFilter(ANCHOR_FALSE_POS2);
// EVIL HACK TEST for #2496 + #2451
assertEquals(ANCHOR_MIXED_RESULT, htmlFilter(ANCHOR_MIXED));
// bug #2451
Expand All @@ -176,7 +181,7 @@ public void testHTMLFilter() throws Exception {
assertTrue(htmlFilter(PREVENT_EXTERNAL_ACCESS_CSS_SIMPLE).contains("div { }"));
assertTrue(htmlFilter(PREVENT_EXTERNAL_ACCESS_CSS_ESCAPE).contains("div { }"));
assertTrue(htmlFilter(PREVENT_EXTERNAL_ACCESS_CSS_CASE).contains("div { }"));
assertEquals(WHITELIST_STATIC_CONTENT, htmlFilter(WHITELIST_STATIC_CONTENT));
testOneHTMLFilter(WHITELIST_STATIC_CONTENT);
assertEquals(XHTML_VOIDELEMENTC, htmlFilter(XHTML_VOIDELEMENT));
assertEquals(XHTML_INCOMPLETEDOCUMENTC, htmlFilter(XHTML_INCOMPLETEDOCUMENT));
assertEquals(XHTML_IMPROPERNESTINGC, htmlFilter(XHTML_IMPROPERNESTING));
Expand All @@ -193,12 +198,13 @@ public void testHTMLFilter() throws Exception {
assertEquals(FRAME_SRC_CHARSET_BADC, htmlFilter(FRAME_SRC_CHARSET_BAD, true));
assertEquals(FRAME_SRC_CHARSET_BAD1C, htmlFilter(FRAME_SRC_CHARSET_BAD1, true));

assertEquals(CSS_SPEC_EXAMPLE1, htmlFilter(CSS_SPEC_EXAMPLE1));
testOneHTMLFilter(CSS_SPEC_EXAMPLE1);

assertEquals(SPAN_WITH_STYLE, htmlFilter(SPAN_WITH_STYLE));
assertEquals(HTML5_TAGS, htmlFilter(HTML5_TAGS));
testOneHTMLFilter(SPAN_WITH_STYLE);
testOneHTMLFilter(HTML5_TAGS);
testOneHTMLFilter(HTML5_BDI_RUBY);

assertEquals(BASE_HREF, htmlFilter(BASE_HREF));
testOneHTMLFilter(BASE_HREF);
assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF));
assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF2));
assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF3));
Expand Down

0 comments on commit 2b02949

Please sign in to comment.