| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
package net.sourceforge.pebble.util; |
| 33 |
|
|
| 34 |
|
import junit.framework.TestCase; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@author |
| 40 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (68) |
Complexity: 6 |
Complexity Density: 0,1 |
|
| 41 |
|
public class StringUtilsTest extends TestCase { |
| 42 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
| 43 |
2
|
public void testTransformHTML() {... |
| 44 |
2
|
assertNull(StringUtils.transformHTML(null)); |
| 45 |
2
|
assertEquals("Here is some text", StringUtils.transformHTML("Here is some text")); |
| 46 |
2
|
assertEquals("Here is a < symbol", StringUtils.transformHTML("Here is a < symbol")); |
| 47 |
2
|
assertEquals("Here is a > symbol", StringUtils.transformHTML("Here is a > symbol")); |
| 48 |
2
|
assertEquals("Here is a & symbol", StringUtils.transformHTML("Here is a & symbol")); |
| 49 |
2
|
assertEquals("<a href="http://www.google.com">Google</a>", StringUtils.transformHTML("<a href=\"http://www.google.com\">Google</a>")); |
| 50 |
|
} |
| 51 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 1 |
Complexity Density: 0,03 |
1
PASS
|
|
| 52 |
2
|
public void testTransformToHTMLSubset() {... |
| 53 |
2
|
assertNull(StringUtils.transformToHTMLSubset(null)); |
| 54 |
2
|
assertEquals("Here is some text", StringUtils.transformToHTMLSubset("Here is some text")); |
| 55 |
2
|
assertEquals("Here is a < symbol", StringUtils.transformToHTMLSubset("Here is a &lt; symbol")); |
| 56 |
2
|
assertEquals("Here is a < symbol", StringUtils.transformToHTMLSubset("Here is a < symbol")); |
| 57 |
2
|
assertEquals("Here is a > symbol", StringUtils.transformToHTMLSubset("Here is a &gt; symbol")); |
| 58 |
2
|
assertEquals("Here is a > symbol", StringUtils.transformToHTMLSubset("Here is a > symbol")); |
| 59 |
2
|
assertEquals("Here is a <b> tag", StringUtils.transformToHTMLSubset("Here is a <b> tag")); |
| 60 |
2
|
assertEquals("Here is a <strong> tag", StringUtils.transformToHTMLSubset("Here is a <strong> tag")); |
| 61 |
2
|
assertEquals("Here is a <i> tag", StringUtils.transformToHTMLSubset("Here is a <i> tag")); |
| 62 |
2
|
assertEquals("Here is a <em> tag", StringUtils.transformToHTMLSubset("Here is a <em> tag")); |
| 63 |
2
|
assertEquals("Here is a <p> tag", StringUtils.transformToHTMLSubset("Here is a <p> tag")); |
| 64 |
2
|
assertEquals("Here is a </p> tag", StringUtils.transformToHTMLSubset("Here is a </p> tag")); |
| 65 |
2
|
assertEquals("Here is a <br /> tag", StringUtils.transformToHTMLSubset("Here is a <br> tag")); |
| 66 |
2
|
assertEquals("Here is a <br /> tag", StringUtils.transformToHTMLSubset("Here is a <br/> tag")); |
| 67 |
2
|
assertEquals("Here is a <br /> tag", StringUtils.transformToHTMLSubset("Here is a <br /> tag")); |
| 68 |
2
|
assertEquals("Here is a <pre> tag", StringUtils.transformToHTMLSubset("Here is a <pre> tag")); |
| 69 |
2
|
assertEquals("Here is a </pre> tag", StringUtils.transformToHTMLSubset("Here is a </pre> tag")); |
| 70 |
2
|
assertEquals("Here is a <a href=\"http://www.google.com\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a <a href="http://www.google.com">link</a> to Google")); |
| 71 |
2
|
assertEquals("Here is a <a href=\"http://www.google.com\">link</a> to Google and another <a href=\"http://www.google.com\">link</a>", StringUtils.transformToHTMLSubset("Here is a <a href="http://www.google.com">link</a> to Google and another <a href="http://www.google.com">link</a>")); |
| 72 |
2
|
assertEquals("Here is a <a href='http://www.google.com'>link</a> to Google", StringUtils.transformToHTMLSubset("Here is a <a href='http://www.google.com'>link</a> to Google")); |
| 73 |
2
|
assertEquals("Here is a <a href='http://www.google.com'>link</a> to Google and another <a href='http://www.google.com'>link</a>", StringUtils.transformToHTMLSubset("Here is a <a href='http://www.google.com'>link</a> to Google and another <a href='http://www.google.com'>link</a>")); |
| 74 |
2
|
assertEquals("Here is a <a href=\"http://www.google.com\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a <a href="http://www.google.com" target="_blank">link</a> to Google")); |
| 75 |
2
|
assertEquals("Here is a <script> tag", StringUtils.transformToHTMLSubset("Here is a <script> tag")); |
| 76 |
2
|
assertEquals("Here is a <blockquote> tag", StringUtils.transformToHTMLSubset("Here is a <blockquote> tag")); |
| 77 |
2
|
assertEquals("Here is a </blockquote> tag", StringUtils.transformToHTMLSubset("Here is a </blockquote> tag")); |
| 78 |
2
|
assertEquals("Here is a <a href=\"mailto:somebody@somedomain.com\">mail link</a>", StringUtils.transformToHTMLSubset("Here is a <a href="mailto:somebody@somedomain.com">mail link</a>")); |
| 79 |
2
|
assertEquals("Here is a ’ character", StringUtils.transformToHTMLSubset("Here is a &#8217; character")); |
| 80 |
2
|
assertEquals("Here is a " symbol", StringUtils.transformToHTMLSubset("Here is a &quot; symbol")); |
| 81 |
2
|
assertEquals("ú", StringUtils.transformToHTMLSubset("&uacute;")); |
| 82 |
2
|
assertEquals("see contracts as "fly-by-night" sorts", StringUtils.transformToHTMLSubset("see contracts as &quot;fly-by-night&quot; sorts")); |
| 83 |
2
|
assertEquals("Here is a <sup> tag", StringUtils.transformToHTMLSubset("Here is a <sup> tag")); |
| 84 |
2
|
assertEquals("Here is a <sub> tag", StringUtils.transformToHTMLSubset("Here is a <sub> tag")); |
| 85 |
|
|
| 86 |
2
|
assertEquals("Here is a <a href=\"https://www.google.com\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a <a href="https://www.google.com">link</a> to Google")); |
| 87 |
2
|
assertEquals("Here is a <a href=\"ftp://www.google.com\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a <a href="ftp://www.google.com">link</a> to Google")); |
| 88 |
|
|
| 89 |
2
|
assertEquals("Here is a <a href=\"\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a <a href="javascript:alert('Hi')">link</a> to Google")); |
| 90 |
|
} |
| 91 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
1
PASS
|
|
| 92 |
2
|
public void testFilterNewLines() {... |
| 93 |
2
|
assertNull(StringUtils.filterNewlines(null)); |
| 94 |
2
|
assertEquals("Here is some text", StringUtils.filterNewlines("Here is some text")); |
| 95 |
2
|
assertEquals("Line 1\n", StringUtils.filterNewlines("Line 1\r\n")); |
| 96 |
2
|
assertEquals("Line 1\nLine2", StringUtils.filterNewlines("Line 1\r\nLine2")); |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
| 99 |
2
|
public void testFilterHTML() {... |
| 100 |
2
|
assertEquals("Here is some text.", StringUtils.filterHTML("Here is <!-- <rdf>...</rdf> -->some text.")); |
| 101 |
2
|
assertEquals("Here is some text.", StringUtils.filterHTML("Here is <!-- <rdf/> -->some text.")); |
| 102 |
2
|
assertEquals("Here is some text.", StringUtils.filterHTML("<b>Here</b> is <i>some</i> text.")); |
| 103 |
2
|
assertEquals("Here is a link.", StringUtils.filterHTML("Here is <a href=\"http://www.google.com\">a link</a>.")); |
| 104 |
2
|
assertEquals("Here is a link.", StringUtils.filterHTML("Here is <a \nhref=\"http://www.google.com\">a link</a>.")); |
| 105 |
2
|
assertEquals("Here is some text", StringUtils.filterHTML("Here is <some> text")); |
| 106 |
|
} |
| 107 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1
PASS
|
|
| 108 |
2
|
public void testStripScriptTags() {... |
| 109 |
2
|
assertEquals("some text", StringUtils.stripScriptTags("some <script>alert(1)</script>text")); |
| 110 |
2
|
assertEquals("some text", StringUtils.stripScriptTags("some <script >alert(1)</script>text")); |
| 111 |
2
|
assertEquals("some text", StringUtils.stripScriptTags("some <script >alert(1)</script >text")); |
| 112 |
2
|
assertEquals("some text", StringUtils.stripScriptTags("some <script language=\"JavaScript\">alert(1)</script >text")); |
| 113 |
2
|
assertEquals("some text", StringUtils.stripScriptTags("some <script src=\"something.js\"/>text")); |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
| 117 |
2
|
public void testUnescapeHTMLEntities() {... |
| 118 |
2
|
assertEquals("\u00A0", StringUtils.unescapeHTMLEntities(" ")); |
| 119 |
2
|
assertEquals("\u00A0\u00A0nbsp\u00A0\u00A0", StringUtils.unescapeHTMLEntities(" nbsp ")); |
| 120 |
2
|
assertEquals("\u00E7", StringUtils.unescapeHTMLEntities("ç")); |
| 121 |
2
|
assertEquals("\u00C7", StringUtils.unescapeHTMLEntities("Ç")); |
| 122 |
2
|
assertEquals("\u03BC\u03BD\u039E", StringUtils.unescapeHTMLEntities("μνΞ")); |
| 123 |
2
|
assertEquals("Seven \u00D0 and eight \u00A3 \u00E7 5 \u2666", StringUtils.unescapeHTMLEntities("Seven Ð and eight £ ç 5 ♦")); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
} |