HtmlAndQueryStringCanonicalizer extends StringCanonicalizer { @Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; } String s = super.execute(content); try { s = StringEscapeUtils.unescapeHtml(s); } catch (Exception e) { throw new IllegalArgumentException("Canonicalization error", e); } try { s = URLDecoder.decode(s, "UTF-8"); } catch (Exception e) { } return s; }  @Override String execute(String content);  }
@Test public void testExecute() throws Exception { HtmlAndQueryStringCanonicalizer canonicalizer = new HtmlAndQueryStringCanonicalizer(); assertEquals("\u00C1", canonicalizer.execute("A\u0301")); assertEquals("\u00F6", canonicalizer.execute("o\u0308")); assertEquals("\u00E1", canonicalizer.execute("a\u0301")); assertEquals(" ", canonicalizer.execute(" ")); assertEquals("", canonicalizer.execute("")); assertEquals(null, canonicalizer.execute(null)); assertEquals("<script", canonicalizer.execute("\u003Cscript")); assertEquals("<script", canonicalizer.execute("&lt;script")); assertEquals("<script", canonicalizer.execute("&#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;")); assertEquals("<script", canonicalizer.execute("%3C%73%63%72%69%70%74")); }