Skip to content
Permalink
Browse files

IDE warning cleanup

  • Loading branch information...
mikesamuel committed Aug 24, 2015
1 parent 42e7d5f commit 024f5563d69c325c2ed00db801730403b0e46bce

Large diffs are not rendered by default.

@@ -41,8 +41,16 @@

import nu.validator.htmlparser.dom.HtmlDocumentBuilder;

/**
* An executable that benchmarks the sanitizer against an alternative.
*/
public class Benchmark {

/**
* By default times all alternatives.
* If there is an input of the form {@code /[hsp]+/} then each letter
* specifies a benchmark to run and unspecified ones are not run.
*/
public static void main(String[] args) throws Exception {
String html = Files.toString(new File(args[0]), Charsets.UTF_8);

@@ -129,7 +137,7 @@ private static int parseUsingLibhtmlparser(String html) throws Exception {
return System.identityHashCode(node) >> 24;
}

private static String sanitize(String html) throws Exception {
private static String sanitize(String html) {
StringBuilder sb = new StringBuilder(html.length());

final HtmlStreamRenderer renderer = HtmlStreamRenderer.create(
@@ -181,8 +189,7 @@ public void closeTag(String elementName) {

private static HtmlPolicyBuilder policyBuilder;

private static String sanitizeUsingPolicyBuilder(String html)
throws Exception {
private static String sanitizeUsingPolicyBuilder(String html) {
if (policyBuilder == null) {
policyBuilder = new HtmlPolicyBuilder()
.allowStandardUrlProtocols()
@@ -38,6 +38,7 @@

import com.google.common.collect.Maps;

@SuppressWarnings("javadoc")
public class CssFuzzerTest extends FuzzyTestCase {

private static final String[] TOKEN_PARTS = new String[] {
@@ -65,9 +66,7 @@ public void run() {
try {
while (true) {
this.wait(1000 /* ms = 1s */);
String input = this.input;
if (input == null) { break; } // Done
long started = this.started;
long now = System.nanoTime();
if (now - started >= 1000000000L /* ns = 1s */) {
System.err.println(
@@ -76,6 +75,7 @@ public void run() {
}
} catch (InterruptedException ex) {
// Done
ignore(ex);
}
}
}
@@ -303,4 +303,9 @@ static String fixDigitSpaceUnit(CssTokens tokens) {
}
return sb.toString();
}

/** @param o ignored */
static void ignore(Object o) {
// Do nothing.
}
}
@@ -37,9 +37,10 @@

import junit.framework.TestCase;

@SuppressWarnings("javadoc")
public class CssGrammarTest extends TestCase {
@Test
public static final void testLex() throws Exception {
public static final void testLex() {
CssTokens tokens = CssTokens.lex(Joiner.on('\n').join(
"/* A comment */",
"words with-dashes #hashes .dots. -and-leading-dashes",
@@ -34,6 +34,7 @@

import junit.framework.TestCase;

@SuppressWarnings("javadoc")
public final class CssSchemaTest extends TestCase {

@Test
@@ -40,6 +40,7 @@

import static org.owasp.html.CssTokens.TokenType.*;

@SuppressWarnings({ "javadoc" })
public class CssTokensTest extends TestCase {

private static CssTokens lex(String s) {
@@ -81,15 +82,15 @@ public static final void testBracketIndices() {
}

@Test
public static final void testStringEscaping() throws Exception {
public static final void testStringEscaping() {
// input golden
String[] tests = {
"''", "''",
"\"\"", "''",
"\"\\a\"", "'\\a'",
"\"\\0d\\0a\"", "'\\d\\a'",
"'\\000000d'", "'\\0 d'", // too many hex digits
"'\\1fffff'", "'\ufffd'", // exceeeds max codepoint
"'\\1fffff'", "'\ufffd'", // exceeds max codepoint
"\"'\"", "'\\27'",
"\"\\\"\"", "'\\22'",
"'\\\\'", "'\\\\'",
@@ -128,7 +129,7 @@ public static final void testStringEscaping() throws Exception {
}

@Test
public static final void testComments() throws Exception {
public static final void testComments() {
assertEquals(
"a b c d e f g h",
lex(
@@ -137,12 +138,12 @@ public static final void testComments() throws Exception {
}

@Test
public static final void testNonCommentSlash() throws Exception {
public static final void testNonCommentSlash() {
assertEquals("foo/ bar/", lex("foo/bar/").normalizedCss);
}

@Test
public static final void testCdoCdc() throws Exception {
public static final void testCdoCdc() {
assertEquals(
"|| and are ignorable||",
lex("||<!-- and --> are ignorable||").normalizedCss);
@@ -152,7 +153,7 @@ public static final void testCdoCdc() throws Exception {
}

@Test
public static final void testIdentReencoding() throws Exception {
public static final void testIdentReencoding() {
// input golden
String[] tests = {
"\\", null,
@@ -222,12 +223,12 @@ public static final void testIdentReencoding() throws Exception {
}

@Test
public static final void testOrphanedCloseBrackets() throws Exception {
public static final void testOrphanedCloseBrackets() {
assertEquals("{foo bar}", lex("{foo]bar").normalizedCss);
}

@Test
public static final void testAtDirectives() throws Exception {
public static final void testAtDirectives() {
assertTokens(
"@import \"foo/bar\"; @ at, @34",
"@import:AT", " ", "'foo/bar':STRING", ";:SEMICOLON",
@@ -236,7 +237,7 @@ public static final void testAtDirectives() throws Exception {
}

@Test
public static final void testHash() throws Exception {
public static final void testHash() {
assertTokens(
"#fff #foo #-moz-foo #abcd #abcdef #012f34 #888 #42foo # #",
"#fff:HASH_UNRESTRICTED", " ",
@@ -251,7 +252,7 @@ public static final void testHash() throws Exception {
}

@Test
public static final void testSignsAndDots() throws Exception {
public static final void testSignsAndDots() {
assertTokens(
"- . + +1 + 1 (1 + 1)--> .5 -.5 +.5 ++.5 .foo -",
"-:IDENT", " ", ".:DELIM", " ", "+:DELIM", " ", "1:NUMBER", " ",
@@ -262,7 +263,7 @@ public static final void testSignsAndDots() throws Exception {
// TODO: is a single "-" an IDENT or a DELIM? "--"? "---"?
}

public static final void testMultiCharPunctuation() throws Exception {
public static final void testMultiCharPunctuation() {
assertTokens(
"|| ~= === |= =^= $= *= = : % & ~",
"||:COLUMN", " ", "~=:MATCH", " ", "=:DELIM", "=:DELIM", "=:DELIM", " ",
@@ -272,13 +273,13 @@ public static final void testMultiCharPunctuation() throws Exception {
}

@Test
public static final void testNul() throws Exception {
public static final void testNul() {
assertTokens("\u0000");
assertTokens("\u0000x\u0000", "x:IDENT");
}

@Test
public static final void testNumbers() throws Exception {
public static final void testNumbers() {
assertTokens(
"0 -0 +0 0.0 -0.0 -.0 0e12 0e-12 0e+12",
"0:NUMBER", " ",
@@ -314,7 +315,7 @@ public static final void testNumbers() throws Exception {
}

@Test
public static final void testUrls() throws Exception {
public static final void testUrls() {
assertTokens(
"url() url('..')url( \"foo\" ) URL( f\"/(bar'\\\\baz ) url('foo \\a b')"
+ "Url( \u0080\u1234\ud801\udc02\\110000)",
@@ -328,7 +329,7 @@ public static final void testUrls() throws Exception {
}

@Test
public static final void testFunctions() throws Exception {
public static final void testFunctions() {
assertTokens("( rgb(0,0,0) rgba(0,50%,0,100%)",
"(:LEFT_PAREN",
" ",
@@ -16,6 +16,7 @@
import static org.owasp.html.ElementPolicy.IDENTITY_ELEMENT_POLICY;
import static org.owasp.html.ElementPolicy.Util.join;

@SuppressWarnings("javadoc")
public final class ElementPolicyTest extends TestCase {

static class HasCharElementPolicy implements ElementPolicy {
@@ -32,7 +32,8 @@

import junit.framework.TestCase;

public class EncodingTest extends TestCase {
@SuppressWarnings("javadoc")
public final class EncodingTest extends TestCase {

@Test
public static final void testDecodeHtml() {
@@ -41,6 +41,7 @@

import junit.framework.TestCase;

@SuppressWarnings("javadoc")
public class ExamplesTest extends TestCase {
@Test
public static final void testExamplesRun() throws Exception {
@@ -38,7 +38,7 @@
* If you see a failure, please report it along with the seed from the output.
* If you want to repeat a failure, set the system property "junit.seed".
*
* @author Mike Samuel <mikesamuel@gmail.com>
* @author Mike Samuel (mikesamuel@gmail.com)
*/
abstract class FuzzyTestCase extends TestCase {

@@ -32,6 +32,7 @@

import junit.framework.TestCase;

@SuppressWarnings("javadoc")
public class HtmlChangeReporterTest extends TestCase {

static class Context {
@@ -39,6 +39,7 @@
import com.google.common.collect.Lists;
import com.google.common.io.Resources;

@SuppressWarnings("javadoc")
public class HtmlLexerTest extends TestCase {

@Test
@@ -60,7 +61,7 @@ public final void testHtmlLexer() throws Exception {
}

@Test
public static final void testEofInTag() throws Exception {
public static final void testEofInTag() {
assertTokens("<div", "TAGBEGIN: <div");
assertTokens("</div", "TAGBEGIN: </div");
assertTokens("<div\n", "TAGBEGIN: <div");
@@ -72,7 +73,7 @@ public static final void testEofInTag() throws Exception {
}

@Test
public static final void testPartialTagInCData() throws Exception {
public static final void testPartialTagInCData() {
assertTokens(
"<script>w('</b')</script>",
"TAGBEGIN: <script",
@@ -83,8 +84,7 @@ public static final void testPartialTagInCData() throws Exception {
}

@Test
public static final void testUrlEndingInSlashOutsideQuotes()
throws Exception {
public static final void testUrlEndingInSlashOutsideQuotes() {
assertTokens(
"<a href=http://foo.com/>Clicky</a>",
"TAGBEGIN: <a",
@@ -97,7 +97,7 @@ public static final void testUrlEndingInSlashOutsideQuotes()
}

@Test
public static final void testShortTags() throws Exception {
public static final void testShortTags() {
// See comments in html-sanitizer-test.js as to why we don't bother with
// short tags. In short, they are not in HTML5 and not implemented properly
// in existing HTML4 clients.
@@ -51,8 +51,9 @@
* If you see a failure, please report it along with the seed from the output.
* If you want to repeat a failure, set the system property "junit.seed".
*
* @author Mike Samuel <mikesamuel@gmail.com>
* @author Mike Samuel (mikesamuel@gmail.com)
*/
@SuppressWarnings("javadoc")
public class HtmlPolicyBuilderFuzzerTest extends FuzzyTestCase {

final Function<HtmlStreamEventReceiver, HtmlSanitizer.Policy> policyFactory

0 comments on commit 024f556

Please sign in to comment.
You can’t perform that action at this time.