Test for [LANG-720] StringEscapeUtils.escapeXml(input) outputs wrong results when an input contains characters in Supplementary Planes. [LANG-708] StringEscapeUtils.escapeEcmaScript from lang3 cuts off long unicode string.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1147212 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2011-07-15 16:12:50 +00:00
parent 4c2ae062ff
commit c04611f260
7 changed files with 44 additions and 3 deletions

View File

@ -24,3 +24,4 @@
repository=${user.home}/.m2/repository repository=${user.home}/.m2/repository
junit.home=${repository}/junit/junit/4.7/ junit.home=${repository}/junit/junit/4.7/
easymock.home=${repository}/org/easymock/easymock/2.5.2/ easymock.home=${repository}/org/easymock/easymock/2.5.2/
commons-io.home=${repository}/commons-io/commons-io/2.0.1/

View File

@ -42,6 +42,7 @@
<pathelement location="${build.home}/tests"/> <pathelement location="${build.home}/tests"/>
<pathelement location="${junit.jar}"/> <pathelement location="${junit.jar}"/>
<pathelement location="${easymock.jar}"/> <pathelement location="${easymock.jar}"/>
<pathelement location="${commons-io.jar}"/>
</path> </path>
<!-- ========== Executable Targets ======================================== --> <!-- ========== Executable Targets ======================================== -->

View File

@ -23,6 +23,9 @@ junit.jar = ${junit.home}/junit-4.7.jar
# The location of the Easymock jar # The location of the Easymock jar
easymock.jar = ${easymock.home}/easymock-2.5.2.jar easymock.jar = ${easymock.home}/easymock-2.5.2.jar
# The location of the Commons-IO jar
commons-io.jar = ${commons-io.home}/commons-io-2.0.1.jar
# Whether or not to fork tests # Whether or not to fork tests
junit.fork = true junit.fork = true

View File

@ -424,6 +424,13 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.easymock</groupId> <groupId>org.easymock</groupId>
<artifactId>easymock</artifactId> <artifactId>easymock</artifactId>

View File

@ -22,6 +22,7 @@
<body> <body>
<release version="3.0" date="Unreleased" description="Backwards incompatible update of Commons Lang to Java 5"> <release version="3.0" date="Unreleased" description="Backwards incompatible update of Commons Lang to Java 5">
<action type="fix" issue="LANG-720">StringEscapeUtils.escapeXml(input) outputs wrong results when an input contains characters in Supplementary Planes.</action>
<action type="update" issue="LANG-718">build.xml Java 1.5+ updates.</action> <action type="update" issue="LANG-718">build.xml Java 1.5+ updates.</action>
<action type="fix" issue="LANG-716">swapCase and *capitalize speedups.</action> <action type="fix" issue="LANG-716">swapCase and *capitalize speedups.</action>
<action type="fix" issue="LANG-715">CharSetUtils.squeeze() speedup.</action> <action type="fix" issue="LANG-715">CharSetUtils.squeeze() speedup.</action>
@ -29,6 +30,7 @@
<action type="update" issue="LANG-713">Increase test coverage of FieldUtils read methods and tweak javadoc</action> <action type="update" issue="LANG-713">Increase test coverage of FieldUtils read methods and tweak javadoc</action>
<action type="fix" issue="LANG-711">Add includeantruntime=false to javac targets to quell warnings in ant 1.8.1 and better (and modest performance gain).</action> <action type="fix" issue="LANG-711">Add includeantruntime=false to javac targets to quell warnings in ant 1.8.1 and better (and modest performance gain).</action>
<action type="fix" issue="LANG-710">StringIndexOutOfBoundsException when calling unescapeHtml4("&amp;#03")</action> <action type="fix" issue="LANG-710">StringIndexOutOfBoundsException when calling unescapeHtml4("&amp;#03")</action>
<action type="fix" issue="LANG-708">StringEscapeUtils.escapeEcmaScript from lang3 cuts off long unicode string</action>
<action type="fix" issue="LANG-703">StringUtils.join throws NPE when toString returns null for one of objects in collection</action> <action type="fix" issue="LANG-703">StringUtils.join throws NPE when toString returns null for one of objects in collection</action>
<action type="add" issue="LANG-697">Add FormattableUtils class</action> <action type="add" issue="LANG-697">Add FormattableUtils class</action>
<action type="add">Add ClassUtils.getSimpleName() methods</action> <action type="add">Add ClassUtils.getSimpleName() methods</action>

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.commons.lang3; package org.apache.commons.lang3;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -23,6 +24,8 @@
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.commons.io.IOUtils;
/** /**
* Unit tests for {@link StringEscapeUtils}. * Unit tests for {@link StringEscapeUtils}.
* *
@ -390,7 +393,11 @@ private void checkCsvUnescapeWriter(String expected, String value) {
} }
} }
// https://issues.apache.org/jira/browse/LANG-480 /**
* Tests // https://issues.apache.org/jira/browse/LANG-480
*
* @throws java.io.UnsupportedEncodingException
*/
public void testEscapeHtmlHighUnicode() throws java.io.UnsupportedEncodingException { public void testEscapeHtmlHighUnicode() throws java.io.UnsupportedEncodingException {
// this is the utf8 representation of the character: // this is the utf8 representation of the character:
// COUNTING ROD UNIT DIGIT THREE // COUNTING ROD UNIT DIGIT THREE
@ -411,7 +418,9 @@ public void testEscapeHtmlHighUnicode() throws java.io.UnsupportedEncodingExcept
// assertEquals( "High unicode should have been unescaped", original, unescapedFromEntity); // assertEquals( "High unicode should have been unescaped", original, unescapedFromEntity);
} }
// https://issues.apache.org/jira/browse/LANG-339 /**
* Tests https://issues.apache.org/jira/browse/LANG-339
*/
public void testEscapeHiragana() { public void testEscapeHiragana() {
// Some random Japanese unicode characters // Some random Japanese unicode characters
String original = "\u304B\u304C\u3068"; String original = "\u304B\u304C\u3068";
@ -424,7 +433,24 @@ public void testEscapeHiragana() {
assertEquals( "Hiragana character unicode behaviour has changed - expected no unescaping", escaped, unescaped); assertEquals( "Hiragana character unicode behaviour has changed - expected no unescaping", escaped, unescaped);
} }
// https://issues.apache.org/jira/browse/LANG-720 /**
* Tests https://issues.apache.org/jira/browse/LANG-708
*
* @throws IOException
* if an I/O error occurs
*/
public void testLang708() throws IOException {
String input = IOUtils.toString(new FileInputStream("src/test/resources/lang-708-input.txt"), "UTF-8");
String escaped = StringEscapeUtils.escapeEcmaScript(input);
// just the end:
assertTrue(escaped, escaped.endsWith("}]"));
// a little more:
assertTrue(escaped, escaped.endsWith("\"valueCode\\\":\\\"\\\"}]"));
}
/**
* Tests https://issues.apache.org/jira/browse/LANG-720
*/
public void testLang720() { public void testLang720() {
String input = new StringBuilder("\ud842\udfb7").append("A").toString(); String input = new StringBuilder("\ud842\udfb7").append("A").toString();
String escaped = StringEscapeUtils.escapeXml(input); String escaped = StringEscapeUtils.escapeXml(input);

File diff suppressed because one or more lines are too long