Implemented TODO to protect unescaper from ArrayIndexOutOfBounds

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1065215 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2011-01-30 08:01:19 +00:00
parent 51bf2ce1c0
commit a95465d709
2 changed files with 10 additions and 2 deletions

View File

@ -34,8 +34,7 @@ public class NumericEntityUnescaper extends CharSequenceTranslator {
*/ */
@Override @Override
public int translate(CharSequence input, int index, Writer out) throws IOException { public int translate(CharSequence input, int index, Writer out) throws IOException {
// TODO: Protect from ArrayIndexOutOfBounds if(input.charAt(index) == '&' && index < (input.length() - 1) && input.charAt(index + 1) == '#') {
if(input.charAt(index) == '&' && input.charAt(index + 1) == '#') {
int start = index + 2; int start = index + 2;
boolean isHex = false; boolean isHex = false;

View File

@ -34,4 +34,13 @@ public void testSupplementaryUnescaping() {
assertEquals("Failed to unescape numeric entities supplementary characters", expected, result); assertEquals("Failed to unescape numeric entities supplementary characters", expected, result);
} }
public void testOutOfBounds() {
NumericEntityUnescaper neu = new NumericEntityUnescaper();
String input = "Test &";
String expected = input;
String result = neu.translate(input);
assertEquals("Failed to ignore when last character is &", expected, result);
}
} }