From e5a1ea6a765cb060104736d64f39a5b2a120896c Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Thu, 22 Nov 2012 02:21:55 +0000 Subject: [PATCH] [LANG-858] StringEscapeUtils.escapeJava() does not output the escaped surrogate pairs that is Java parsable. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1412408 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/lang3/StringUtilsTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index e3ceea3af..31cf6ad95 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -36,6 +36,7 @@ import java.util.Iterator; import java.util.Locale; import org.apache.commons.lang3.text.WordUtils; +import org.junit.Ignore; import org.junit.Test; /** @@ -2189,5 +2190,31 @@ public class StringUtilsTest { assertEquals("\uD800\uDC00", StringEscapeUtils.escapeCsv("\uD800\uDC00")); assertEquals("\uD834\uDD1E", StringEscapeUtils.escapeCsv("\uD834\uDD1E")); assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeCsv("\uDBFF\uDFFD")); + assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeHtml3("\uDBFF\uDFFD")); + assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeHtml4("\uDBFF\uDFFD")); + assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeXml("\uDBFF\uDFFD")); + } + + /** + * Tests LANG-858. + * + * @throws Exception + */ + @Test + @Ignore + public void testEscapeSurrogatePairsLang858() throws Exception { + assertEquals("\\uDBFF\\uDFFD", StringEscapeUtils.escapeJava("\uDBFF\uDFFD")); //fail LANG-858 + assertEquals("\\uDBFF\\uDFFD", StringEscapeUtils.escapeEcmaScript("\uDBFF\uDFFD")); //fail LANG-858 + } + + @Test + public void testUnescapeSurrogatePairs() throws Exception { + assertEquals("\uD83D\uDE30", StringEscapeUtils.unescapeCsv("\uD83D\uDE30")); + // Examples from https://en.wikipedia.org/wiki/UTF-16 + assertEquals("\uD800\uDC00", StringEscapeUtils.unescapeCsv("\uD800\uDC00")); + assertEquals("\uD834\uDD1E", StringEscapeUtils.unescapeCsv("\uD834\uDD1E")); + assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeCsv("\uDBFF\uDFFD")); + assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeHtml3("\uDBFF\uDFFD")); + assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeHtml4("\uDBFF\uDFFD")); } }