Replacing the optimisation for LANG-287.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@504334 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/commons/lang/Entities.java b/src/java/org/apache/commons/lang/Entities.java
index 9a6c8ff..725ed10 100644
--- a/src/java/org/apache/commons/lang/Entities.java
+++ b/src/java/org/apache/commons/lang/Entities.java
@@ -858,15 +858,20 @@
* @return A new escaped <code>String</code>.
*/
public String unescape(String str) {
- StringWriter stringWriter = createStringWriter(str);
- try {
- this.unescape(stringWriter, str);
- } catch (IOException e) {
- // This should never happen because ALL the StringWriter methods called by #escape(Writer, String) do not
- // throw IOExceptions.
- throw new UnhandledException(e);
+ int firstAmp = str.indexOf('&');
+ if (firstAmp < 0) {
+ return str;
+ } else {
+ StringWriter stringWriter = createStringWriter(str);
+ try {
+ this.doUnescape(stringWriter, str, firstAmp);
+ } catch (IOException e) {
+ // This should never happen because ALL the StringWriter methods called by #escape(Writer, String) do not
+ // throw IOExceptions.
+ throw new UnhandledException(e);
+ }
+ return stringWriter.toString();
}
- return stringWriter.toString();
}
private StringWriter createStringWriter(String str) {
@@ -896,8 +901,12 @@
if (firstAmp < 0) {
writer.write(string);
return;
+ } else {
+ doUnescape(writer, string, firstAmp);
}
+ }
+ private void doUnescape(Writer writer, String string, int firstAmp) throws IOException {
writer.write(string, 0, firstAmp);
int len = string.length();
for (int i = firstAmp; i < len; i++) {