QueryStringCanonicalizer extends StringCanonicalizer { @Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; } String s = super.execute(content); try { s = URLDecoder.decode(s, "UTF-8"); } catch (Exception e) { throw new RuntimeException(e); } return s; }  @Override String execute(String content);  }
@Test public void testExecute() throws Exception { QueryStringCanonicalizer canonicalizer = new QueryStringCanonicalizer(); 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(" ", canonicalizer.execute("+")); assertEquals(null, canonicalizer.execute(null)); assertEquals("<script", canonicalizer.execute("\u003Cscript")); assertEquals("&lt;script", canonicalizer.execute("&lt;script")); assertEquals("&#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;", canonicalizer.execute("&#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;")); assertEquals("<script", canonicalizer.execute("%3C%73%63%72%69%70%74")); try { canonicalizer.execute("data%3atext%2fht%%206dl%3bbase64%2cPHdoc2N%20oZWNrPg%3d%3d"); fail("Should throw IllegalArgumentException"); } catch (Exception e) { assertTrue(ExceptionUtils.getCause(e) instanceof IllegalArgumentException); } }