Fixing issue #38569

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@394875 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2006-04-18 07:23:02 +00:00
parent 4143a12a0e
commit 2330a3343c
2 changed files with 22 additions and 1 deletions

View File

@ -820,6 +820,12 @@ class Entities {
buf.append(ch);
continue;
}
int amph = str.indexOf('&', i + 1);
if( amph != -1 && amph < semi ) {
// Then the text looks like &...&...;
buf.append(ch);
continue;
}
String entityName = str.substring(i + 1, semi);
int entityValue;
if (entityName.length() == 0) {
@ -883,6 +889,12 @@ class Entities {
writer.write(c);
continue;
}
int amphersandIdx = string.indexOf('&', i + 1);
if( amphersandIdx != -1 && amphersandIdx < semiColonIdx ) {
// Then the text looks like &...&...;
writer.write(c);
continue;
}
String entityContent = string.substring(nextIdx, semiColonIdx);
int entityValue = -1;
int entityContentLen = entityContent.length();

View File

@ -302,5 +302,14 @@ public class StringEscapeUtilsTest extends TestCase {
assertEquals("", StringEscapeUtils.escapeSql(""));
assertEquals(null, StringEscapeUtils.escapeSql(null));
}
}
// Tests issue #38569
// http://issues.apache.org/bugzilla/show_bug.cgi?id=38569
public void testStandaloneAmphersand() {
assertEquals("<P&O>", StringEscapeUtils.unescapeHtml("&lt;P&O&gt;"));
assertEquals("test & <", StringEscapeUtils.unescapeHtml("test & &lt;"));
assertEquals("<P&O>", StringEscapeUtils.unescapeXml("&lt;P&O&gt;"));
assertEquals("test & <", StringEscapeUtils.unescapeXml("test & &lt;"));
}
}