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:
parent
51bf2ce1c0
commit
a95465d709
|
@ -34,8 +34,7 @@ public class NumericEntityUnescaper extends CharSequenceTranslator {
|
|||
*/
|
||||
@Override
|
||||
public int translate(CharSequence input, int index, Writer out) throws IOException {
|
||||
// TODO: Protect from ArrayIndexOutOfBounds
|
||||
if(input.charAt(index) == '&' && input.charAt(index + 1) == '#') {
|
||||
if(input.charAt(index) == '&' && index < (input.length() - 1) && input.charAt(index + 1) == '#') {
|
||||
int start = index + 2;
|
||||
boolean isHex = false;
|
||||
|
||||
|
|
|
@ -34,4 +34,13 @@ public void testSupplementaryUnescaping() {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue