/** Tests that if specify '%' as safe the result is an idempotent escaper. */ public void testCustomEscaper_withpercent() { UnicodeEscaper e = new PercentEscaper("%", false); assertEquals("foo%7Cbar", e.escape("foo|bar")); assertEquals("foo%7Cbar", e.escape("foo%7Cbar")); // idempotent }
/** Tests the various ways that the space character can be handled */ public void testPlusForSpace() { UnicodeEscaper basicEscaper = new PercentEscaper("", false); UnicodeEscaper plusForSpaceEscaper = new PercentEscaper("", true); UnicodeEscaper spaceEscaper = new PercentEscaper(" ", false); assertEquals("string%20with%20spaces", basicEscaper.escape("string with spaces")); assertEquals("string+with+spaces", plusForSpaceEscaper.escape("string with spaces")); assertEquals("string with spaces", spaceEscaper.escape("string with spaces")); }
/** Tests that the simple escaper treats 0-9, a-z and A-Z as safe */ public void testSimpleEscaper() { UnicodeEscaper e = new PercentEscaper("", false); for (char c = 0; c < 128; c++) { if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { assertUnescaped(e, c); } else { assertEscaping(e, escapeAscii(c), c); } } // Testing mutlibyte escape sequences assertEscaping(e, "%00", '\u0000'); // nul assertEscaping(e, "%7F", '\u007f'); // del assertEscaping(e, "%C2%80", '\u0080'); // xx-00010,x-000000 assertEscaping(e, "%DF%BF", '\u07ff'); // xx-11111,x-111111 assertEscaping(e, "%E0%A0%80", '\u0800'); // xxx-0000,x-100000,x-00,0000 assertEscaping(e, "%EF%BF%BF", '\uffff'); // xxx-1111,x-111111,x-11,1111 assertUnicodeEscaping(e, "%F0%90%80%80", '\uD800', '\uDC00'); assertUnicodeEscaping(e, "%F4%8F%BF%BF", '\uDBFF', '\uDFFF'); // simple string tests assertEquals("", e.escape("")); assertEquals("safestring", e.escape("safestring")); assertEquals("embedded%00null", e.escape("embedded\0null")); assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar")); }
/** Tests that if specify '%' as safe the result is an idempotent escaper. */ public void testCustomEscaper_withpercent() { UnicodeEscaper e = new PercentEscaper("%", false); assertEquals("foo%7Cbar", e.escape("foo|bar")); assertEquals("foo%7Cbar", e.escape("foo%7Cbar")); // idempotent }
/** Tests the various ways that the space character can be handled */ public void testPlusForSpace() { UnicodeEscaper basicEscaper = new PercentEscaper("", false); UnicodeEscaper plusForSpaceEscaper = new PercentEscaper("", true); UnicodeEscaper spaceEscaper = new PercentEscaper(" ", false); assertEquals("string%20with%20spaces", basicEscaper.escape("string with spaces")); assertEquals("string+with+spaces", plusForSpaceEscaper.escape("string with spaces")); assertEquals("string with spaces", spaceEscaper.escape("string with spaces")); }
/** Tests that the simple escaper treats 0-9, a-z and A-Z as safe */ public void testSimpleEscaper() { UnicodeEscaper e = new PercentEscaper("", false); for (char c = 0; c < 128; c++) { if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { assertUnescaped(e, c); } else { assertEscaping(e, escapeAscii(c), c); } } // Testing mutlibyte escape sequences assertEscaping(e, "%00", '\u0000'); // nul assertEscaping(e, "%7F", '\u007f'); // del assertEscaping(e, "%C2%80", '\u0080'); // xx-00010,x-000000 assertEscaping(e, "%DF%BF", '\u07ff'); // xx-11111,x-111111 assertEscaping(e, "%E0%A0%80", '\u0800'); // xxx-0000,x-100000,x-00,0000 assertEscaping(e, "%EF%BF%BF", '\uffff'); // xxx-1111,x-111111,x-11,1111 assertUnicodeEscaping(e, "%F0%90%80%80", '\uD800', '\uDC00'); assertUnicodeEscaping(e, "%F4%8F%BF%BF", '\uDBFF', '\uDFFF'); // simple string tests assertEquals("", e.escape("")); assertEquals("safestring", e.escape("safestring")); assertEquals("embedded%00null", e.escape("embedded\0null")); assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar")); }