1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.xml.internal.html; |
21 |
|
|
22 |
|
import java.io.StringReader; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
|
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Ignore; |
31 |
|
import org.junit.Rule; |
32 |
|
import org.junit.Test; |
33 |
|
import org.xwiki.component.manager.ComponentLookupException; |
34 |
|
import org.xwiki.test.annotation.ComponentList; |
35 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
36 |
|
import org.xwiki.xml.html.HTMLCleaner; |
37 |
|
import org.xwiki.xml.html.HTMLCleanerConfiguration; |
38 |
|
import org.xwiki.xml.html.HTMLUtils; |
39 |
|
import org.xwiki.xml.html.filter.HTMLFilter; |
40 |
|
import org.xwiki.xml.internal.html.filter.AttributeFilter; |
41 |
|
import org.xwiki.xml.internal.html.filter.BodyFilter; |
42 |
|
import org.xwiki.xml.internal.html.filter.FontFilter; |
43 |
|
import org.xwiki.xml.internal.html.filter.LinkFilter; |
44 |
|
import org.xwiki.xml.internal.html.filter.ListFilter; |
45 |
|
import org.xwiki.xml.internal.html.filter.ListItemFilter; |
46 |
|
import org.xwiki.xml.internal.html.filter.UniqueIdFilter; |
47 |
|
|
48 |
|
|
49 |
|
@link |
50 |
|
|
51 |
|
@version |
52 |
|
@since |
53 |
|
|
54 |
|
@ComponentList({ ListFilter.class, ListItemFilter.class, FontFilter.class, BodyFilter.class, AttributeFilter.class, |
55 |
|
UniqueIdFilter.class, DefaultHTMLCleaner.class, LinkFilter.class }) |
|
|
| 92.6% |
Uncovered Elements: 9 (121) |
Complexity: 22 |
Complexity Density: 0.22 |
|
56 |
|
public class DefaultHTMLCleanerTest |
57 |
|
{ |
58 |
|
public static final String HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
59 |
|
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " |
60 |
|
+ "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; |
61 |
|
|
62 |
|
private static final String HEADER_FULL = HEADER + "<html><head></head><body>"; |
63 |
|
|
64 |
|
private static final String FOOTER = "</body></html>\n"; |
65 |
|
|
66 |
|
@Rule |
67 |
|
public final MockitoComponentMockingRule<HTMLCleaner> mocker = new MockitoComponentMockingRule<HTMLCleaner>( |
68 |
|
DefaultHTMLCleaner.class); |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
public void elementExpansion() throws ComponentLookupException |
72 |
|
{ |
73 |
1 |
assertHTML("<p><textarea></textarea></p>", "<textarea/>"); |
74 |
|
|
75 |
|
|
76 |
1 |
assertHTML("<p><br /></p>", "<p><br></p>"); |
77 |
1 |
assertHTML("<hr />", "<hr>"); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void specialCharacters() throws ComponentLookupException |
82 |
|
{ |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
1 |
assertHTML("<p>"&**notbold**<notag> </p>", |
88 |
|
"<p>"&**notbold**<notag> </p>"); |
89 |
1 |
assertHTML("<p>\"&</p>", "<p>\"&</p>"); |
90 |
1 |
assertHTML("<p><img src=\"http://host.com/a.gif?a=foo&b=bar\" /></p>", |
91 |
|
"<img src=\"http://host.com/a.gif?a=foo&b=bar\" />"); |
92 |
1 |
assertHTML("<p>
</p>", "<p>
</p>"); |
93 |
|
|
94 |
|
|
95 |
1 |
assertHTML("<p value=\"script:""\"></p>", "<p value='script:\"\"'"); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void closeUnbalancedTags() throws ComponentLookupException |
100 |
|
{ |
101 |
1 |
assertHTML("<hr /><p>hello</p>", "<hr><p>hello"); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
104 |
1 |
@Test... |
105 |
|
public void conversionsFromHTML() throws ComponentLookupException |
106 |
|
{ |
107 |
1 |
assertHTML("<p>this <strong>is</strong> bold</p>", "this <b>is</b> bold"); |
108 |
1 |
assertHTML("<p><em>italic</em></p>", "<i>italic</i>"); |
109 |
1 |
assertHTML("<del>strike</del>", "<strike>strike</strike>"); |
110 |
1 |
assertHTML("<del>strike</del>", "<s>strike</s>"); |
111 |
1 |
assertHTML("<ins>strike</ins>", "<u>strike</u>"); |
112 |
1 |
assertHTML("<p style=\"text-align:center\">center</p>", "<center>center</center>"); |
113 |
1 |
assertHTML("<p><span style=\"color:red;font-family:Arial;font-size:1.0em;\">This is some text!</span></p>", |
114 |
|
"<font face=\"Arial\" size=\"3\" color=\"red\">This is some text!</font>"); |
115 |
1 |
assertHTML("<p><span style=\"font-size:1.6em;\">This is some text!</span></p>", |
116 |
|
"<font size=\"+3\">This is some text!</font>"); |
117 |
1 |
assertHTML("<table><tbody><tr><td style=\"text-align:right;background-color:red;vertical-align:top\">" |
118 |
|
+ "x</td></tr></tbody></table>", "<table><tr><td align=right valign=top bgcolor=red>x</td></tr></table>"); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
121 |
1 |
@Test... |
122 |
|
public void convertImageAlignment() throws ComponentLookupException |
123 |
|
{ |
124 |
1 |
assertHTML("<p><img style=\"float:left\" /></p>", "<img align=\"left\"/>"); |
125 |
1 |
assertHTML("<p><img style=\"float:right\" /></p>", "<img align=\"right\"/>"); |
126 |
1 |
assertHTML("<p><img style=\"vertical-align:top\" /></p>", "<img align=\"top\"/>"); |
127 |
1 |
assertHTML("<p><img style=\"vertical-align:middle\" /></p>", "<img align=\"middle\"/>"); |
128 |
1 |
assertHTML("<p><img style=\"vertical-align:bottom\" /></p>", "<img align=\"bottom\"/>"); |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
131 |
1 |
@Test... |
132 |
|
public void convertImplicitParagraphs() throws ComponentLookupException |
133 |
|
{ |
134 |
1 |
assertHTML("<p>word1</p><p>word2</p><p>word3</p><hr /><p>word4</p>", "word1<p>word2</p>word3<hr />word4"); |
135 |
|
|
136 |
|
|
137 |
1 |
assertHTML("<p>word1</p> \n <p>word2</p>", "<p>word1</p> \n <p>word2</p>"); |
138 |
|
|
139 |
|
|
140 |
1 |
assertHTML("\n ", "\n "); |
141 |
|
|
142 |
|
|
143 |
1 |
assertHTML("<!-- comment1 -->\n<p>hello</p>\n<!-- comment2 -->", |
144 |
|
"<!-- comment1 -->\n<p>hello</p>\n<!-- comment2 -->"); |
145 |
|
|
146 |
|
|
147 |
1 |
assertHTML("<!-- comment --><p><span>hello</span><!-- comment --></p><p>world</p>", |
148 |
|
"<!-- comment --><span>hello</span><!-- comment --><p>world</p>"); |
149 |
|
} |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
151 |
1 |
@Test... |
152 |
|
public void cleanNonXHTMLLists() throws ComponentLookupException |
153 |
|
{ |
154 |
|
|
155 |
1 |
assertHTML("<ul><li>item</li></ul>", "<li>item</li>"); |
156 |
|
|
157 |
1 |
assertHTML("<ul><li>item1<ul><li>item2</li></ul></li></ul>", "<ul><li>item1</li><ul><li>item2</li></ul></ul>"); |
158 |
1 |
assertHTML("<ul><li>item1<ul><li>item2<ul><li>item3</li></ul></li></ul></li></ul>", |
159 |
|
"<ul><li>item1</li><ul><li>item2</li><ul><li>item3</li></ul></ul></ul>"); |
160 |
1 |
assertHTML("<ul><li style=\"list-style-type: none\"><ul><li>item</li></ul></li></ul>", |
161 |
|
"<ul><ul><li>item</li></ul></ul>"); |
162 |
1 |
assertHTML("<ul> <li style=\"list-style-type: none\"><ul><li>item</li></ul></li></ul>", |
163 |
|
"<ul> <ul><li>item</li></ul></ul>"); |
164 |
1 |
assertHTML("<ul><li>item1<ol><li>item2</li></ol></li></ul>", "<ul><li>item1</li><ol><li>item2</li></ol></ul>"); |
165 |
1 |
assertHTML("<ol><li>item1<ol><li>item2<ol><li>item3</li></ol></li></ol></li></ol>", |
166 |
|
"<ol><li>item1</li><ol><li>item2</li><ol><li>item3</li></ol></ol></ol>"); |
167 |
1 |
assertHTML("<ol><li style=\"list-style-type: none\"><ol><li>item</li></ol></li></ol>", |
168 |
|
"<ol><ol><li>item</li></ol></ol>"); |
169 |
1 |
assertHTML("<ul><li>item1<ul><li style=\"list-style-type: none\"><ul><li>item2</li></ul></li>" |
170 |
|
+ "<li>item3</li></ul></li></ul>", "<ul><li>item1</li><ul><ul><li>item2</li></ul><li>item3</li></ul></ul>"); |
171 |
|
|
172 |
1 |
assertHTML("<ul>\n\n<li style=\"list-style-type: none\"><p>text</p></li></ul>", "<ul>\n\n<p>text</p></ul>"); |
173 |
1 |
assertHTML("<ul><li>item<p>text</p></li><!--x--> </ul>", "<ul><li>item</li><!--x--> <p>text</p></ul>"); |
174 |
1 |
assertHTML("<ul> \n<li style=\"list-style-type: none\"><em>1</em>2<ins>3</ins></li><!--x--><li>item</li></ul>", |
175 |
|
"<ul> \n<em>1</em><!--x-->2<ins>3</ins><li>item</li></ul>"); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
181 |
1 |
@Test... |
182 |
|
public void scriptAndCData() throws ComponentLookupException |
183 |
|
{ |
184 |
1 |
assertHTML("<script type=\"text/javascript\">//<![CDATA[\n\nalert(\"Hello World\")\n\n//]]></script>", |
185 |
|
"<script type=\"text/javascript\"><![CDATA[\nalert(\"Hello World\")\n]]></script>"); |
186 |
|
|
187 |
1 |
assertHTML("<script type=\"text/javascript\">//<![CDATA[\n//\nalert(\"Hello World\")\n\n//]]></script>", |
188 |
|
"<script type=\"text/javascript\">//<![CDATA[\nalert(\"Hello World\")\n//]]></script>"); |
189 |
|
|
190 |
1 |
assertHTML("<script type=\"text/javascript\">//<![CDATA[\n\nalert(\"Hello World\")\n\n//]]></script>", |
191 |
|
"<script type=\"text/javascript\">/*<![CDATA[*/\nalert(\"Hello World\")\n/*]]>*/</script>"); |
192 |
|
|
193 |
1 |
assertHTML("<script type=\"text/javascript\">//<![CDATA[\n\n\n" + "function escapeForXML(origtext) {\n" |
194 |
|
+ " return origtext.replace(/\\&/g,'&'+'amp;').replace(/</g,'&'+'lt;')\n" |
195 |
|
+ " .replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');" + "}\n\n\n//]]>" |
196 |
|
+ "</script>", "<script type=\"text/javascript\">\n" + "/*<![CDATA[*/\n" |
197 |
|
+ "function escapeForXML(origtext) {\n" |
198 |
|
+ " return origtext.replace(/\\&/g,'&'+'amp;').replace(/</g,'&'+'lt;')\n" |
199 |
|
+ " .replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');" + "}\n" |
200 |
|
+ "/*]]>*/\n" + "</script>"); |
201 |
|
|
202 |
1 |
assertHTML("<script>//<![CDATA[\n<>\n//]]></script>", "<script><></script>"); |
203 |
1 |
assertHTML("<script>//<![CDATA[\n<>\n//]]></script>", "<script><></script>"); |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
1 |
assertHTML("<p></p>", "<p><![CDATA[&]]></p>"); |
208 |
1 |
assertHTML("<p>&&</p>", "<p>&<![CDATA[&]]>&</p>"); |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
214 |
1 |
@Test... |
215 |
|
public void styleAndCData() throws ComponentLookupException |
216 |
|
{ |
217 |
1 |
assertHTMLWithHeadContent("<style type=\"text/css\">/*<![CDATA[*/\na { color: red; }\n/*]]>*/</style>", |
218 |
|
"<style type=\"text/css\"><![CDATA[\na { color: red; }\n]]></style>"); |
219 |
|
|
220 |
1 |
assertHTMLWithHeadContent("<style type=\"text/css\">/*<![CDATA[*/\na { color: red; }\n/*]]>*/</style>", |
221 |
|
"<style type=\"text/css\">/*<![CDATA[*/\na { color: red; }\n/*]]>*/</style>"); |
222 |
|
|
223 |
1 |
assertHTMLWithHeadContent("<style type=\"text/css\">/*<![CDATA[*/a>span { color: blue;}\n/*]]>*/</style>", |
224 |
|
"<style type=\"text/css\">a>span { color: blue;}</style>"); |
225 |
|
|
226 |
1 |
assertHTMLWithHeadContent("<style>/*<![CDATA[*/<>\n/*]]>*/</style>", "<style><></style>"); |
227 |
1 |
assertHTMLWithHeadContent("<style>/*<![CDATA[*/<>\n/*]]>*/</style>", "<style><></style>"); |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
233 |
1 |
@Test... |
234 |
|
public void explicitFilterList() throws ComponentLookupException |
235 |
|
{ |
236 |
1 |
HTMLCleanerConfiguration configuration = this.mocker.getComponentUnderTest().getDefaultConfiguration(); |
237 |
1 |
configuration.setFilters(Collections.<HTMLFilter>emptyList()); |
238 |
1 |
String result = |
239 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader("something"), configuration)); |
240 |
|
|
241 |
|
|
242 |
1 |
Assert.assertEquals(HEADER_FULL + "something" + FOOTER, result); |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
248 |
1 |
@Test... |
249 |
|
public void restrictedHtml() throws ComponentLookupException |
250 |
|
{ |
251 |
1 |
HTMLCleanerConfiguration configuration = this.mocker.getComponentUnderTest().getDefaultConfiguration(); |
252 |
1 |
Map<String, String> parameters = new HashMap<String, String>(); |
253 |
1 |
parameters.putAll(configuration.getParameters()); |
254 |
1 |
parameters.put("restricted", "true"); |
255 |
1 |
configuration.setParameters(parameters); |
256 |
|
|
257 |
1 |
String result = |
258 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean( |
259 |
|
new StringReader("<script>alert(\"foo\")</script>"), configuration)); |
260 |
1 |
Assert.assertEquals(HEADER_FULL + "<pre>alert(\"foo\")</pre>" + FOOTER, result); |
261 |
|
|
262 |
1 |
result = |
263 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean( |
264 |
|
new StringReader("<style>p {color:white;}</style>"), configuration)); |
265 |
1 |
Assert.assertEquals(HEADER_FULL + "<pre>p {color:white;}</pre>" + FOOTER, result); |
266 |
|
|
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
272 |
1 |
@Test... |
273 |
|
public void fullXHTMLHeader() throws ComponentLookupException |
274 |
|
{ |
275 |
1 |
assertHTML("<p>test</p>", HEADER_FULL + "<p>test</p>" + FOOTER); |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
@link |
280 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
281 |
1 |
@Test... |
282 |
|
public void duplicateIds() throws Exception |
283 |
|
{ |
284 |
1 |
String actual = "<p id=\"x\">1</p><p id=\"xy\">2</p><p id=\"x\">3</p>"; |
285 |
1 |
String expected = "<p id=\"x\">1</p><p id=\"xy\">2</p><p id=\"x0\">3</p>"; |
286 |
1 |
HTMLCleanerConfiguration config = this.mocker.getComponentUnderTest().getDefaultConfiguration(); |
287 |
1 |
List<HTMLFilter> filters = new ArrayList<HTMLFilter>(config.getFilters()); |
288 |
1 |
filters.add(this.mocker.<HTMLFilter>getInstance(HTMLFilter.class, "uniqueId")); |
289 |
1 |
config.setFilters(filters); |
290 |
1 |
Assert.assertEquals(HEADER_FULL + expected + FOOTER, |
291 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(actual), config))); |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
298 |
1 |
@Test... |
299 |
|
public void cleanSVGTags() throws Exception |
300 |
|
{ |
301 |
1 |
String input = |
302 |
|
"<p>before</p>\n" + "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n" |
303 |
|
+ "<circle cx=\"100\" cy=\"50\" fill=\"red\" r=\"40\" stroke=\"black\" stroke-width=\"2\"></circle>\n" |
304 |
|
+ "</svg>\n" + "<p>after</p>\n"; |
305 |
1 |
assertHTML(input, HEADER_FULL + input + FOOTER); |
306 |
|
} |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
313 |
0 |
@Test... |
314 |
|
@Ignore("See http://jira.xwiki.org/browse/XWIKI-9753") |
315 |
|
public void cleanTitleWithNamespace() throws Exception |
316 |
|
{ |
317 |
|
|
318 |
0 |
String input = |
319 |
|
"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n" |
320 |
|
+ " <head>\n" |
321 |
|
+ " <title>Title test</title>\n" |
322 |
|
+ " </head>\n" |
323 |
|
+ " <body>\n" |
324 |
|
+ " <p>before</p>\n" |
325 |
|
+ " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"300\" width=\"500\">\n" |
326 |
|
+ " <g>\n" |
327 |
|
+ " <title>SVG Title Demo example</title>\n" |
328 |
|
+ " <rect height=\"50\" style=\"fill:none; stroke:blue; stroke-width:1px\" width=\"200\" x=\"10\" " |
329 |
|
+ "y=\"10\"></rect>\n" + " </g>\n" + " </svg>\n" + " <p>after</p>\n"; |
330 |
0 |
Assert.assertEquals(HEADER + input + FOOTER, |
331 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(input)))); |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
@link |
337 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
338 |
0 |
@Test... |
339 |
|
@Ignore("See https://sourceforge.net/p/htmlcleaner/bugs/168/") |
340 |
|
public void cleanHTMLTagWithNamespace() throws Exception |
341 |
|
{ |
342 |
0 |
String input = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body>"; |
343 |
|
|
344 |
|
|
345 |
0 |
Assert.assertEquals(HEADER + input + FOOTER, |
346 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(input)))); |
347 |
|
|
348 |
|
|
349 |
0 |
HTMLCleanerConfiguration config = this.mocker.getComponentUnderTest().getDefaultConfiguration(); |
350 |
0 |
config.setParameters(Collections.singletonMap(HTMLCleanerConfiguration.NAMESPACES_AWARE, "false")); |
351 |
0 |
Assert.assertEquals(HEADER + "<html><head></head><body>" + FOOTER, |
352 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(input), config))); |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
359 |
1 |
@Test... |
360 |
|
public void cleanEmptyDIV() throws Exception |
361 |
|
{ |
362 |
1 |
String input = "<div id=\"y\"></div><div id=\"z\">something</div>"; |
363 |
1 |
assertHTML(input, HEADER_FULL + input + FOOTER); |
364 |
|
} |
365 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
366 |
1 |
@Test... |
367 |
|
public void verifyLegendTagNotStripped() throws Exception |
368 |
|
{ |
369 |
1 |
String input = "<fieldset><legend>test</legend><div>content</div></fieldset>"; |
370 |
1 |
assertHTML(input, HEADER_FULL + input + FOOTER); |
371 |
|
} |
372 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
373 |
1 |
@Test... |
374 |
|
public void verifySpanIsExpanded() throws Exception |
375 |
|
{ |
376 |
1 |
assertHTML("<p><span class=\"fa fa-icon\"></span></p>", "<span class=\"fa fa-icon\" />"); |
377 |
|
} |
378 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
379 |
1 |
@Test... |
380 |
|
public void verifyExternalLinksAreSecure() throws Exception |
381 |
|
{ |
382 |
1 |
assertHTML("<p><a href=\"relativeLink\" target=\"_blank\">label</a></p>", |
383 |
|
"<a href=\"relativeLink\" target=\"_blank\">label</a>"); |
384 |
1 |
assertHTML("<p><a href=\"http://xwiki.org\" rel=\" noopener noreferrer\" target=\"_blank\">label</a></p>", |
385 |
|
"<a href=\"http://xwiki.org\" target=\"_blank\">label</a>"); |
386 |
1 |
assertHTML("<p><a href=\"http://xwiki.org\" rel=\" noopener noreferrer\" target=\"someframe\">label</a></p>", |
387 |
|
"<a href=\"http://xwiki.org\" target=\"someframe\">label</a>"); |
388 |
1 |
assertHTML("<p><a href=\"http://xwiki.org\" target=\"_top\">label</a></p>", |
389 |
|
"<a href=\"http://xwiki.org\" target=\"_top\">label</a>"); |
390 |
1 |
assertHTML("<p><a href=\"http://xwiki.org\" target=\"_parent\">label</a></p>", |
391 |
|
"<a href=\"http://xwiki.org\" target=\"_parent\">label</a>"); |
392 |
1 |
assertHTML("<p><a href=\"http://xwiki.org\" target=\"_self\">label</a></p>", |
393 |
|
"<a href=\"http://xwiki.org\" target=\"_self\">label</a>"); |
394 |
1 |
assertHTML("<p><a href=\"http://xwiki.org\" rel=\"noopener noreferrer\" target=\"_blank\">label</a></p>", |
395 |
|
"<a href=\"http://xwiki.org\" target=\"_blank\" rel=\"noopener\">label</a>"); |
396 |
1 |
assertHTML("<p><a href=\"http://xwiki.org\" rel=\"noreferrer noopener\" target=\"_blank\">label</a></p>", |
397 |
|
"<a href=\"http://xwiki.org\" target=\"_blank\" rel=\"noreferrer\">label</a>"); |
398 |
1 |
assertHTML("<p><a href=\"http://xwiki.org\" rel=\"hello noopener noreferrer\" target=\"_blank\">label</a></p>", |
399 |
|
"<a href=\"http://xwiki.org\" target=\"_blank\" rel=\"hello\">label</a>"); |
400 |
|
} |
401 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
402 |
62 |
private void assertHTML(String expected, String actual) throws ComponentLookupException... |
403 |
|
{ |
404 |
62 |
Assert.assertEquals(HEADER_FULL + expected + FOOTER, |
405 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(actual)))); |
406 |
|
} |
407 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
408 |
5 |
private void assertHTMLWithHeadContent(String expected, String actual) throws ComponentLookupException... |
409 |
|
{ |
410 |
5 |
Assert.assertEquals(HEADER + "<html><head>" + expected + "</head><body>" + FOOTER, |
411 |
|
HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(actual)))); |
412 |
|
} |
413 |
|
} |