Applying github pull request https://github.com/apache/commons-lang/pull/5, linked as LANG-928, fixing a bug in OctalEscaper trying to parse octal numbers longer than 3 digits

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1535911 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2013-10-26 02:14:35 +00:00
parent 38f8b88528
commit 6ea7f2f7af
3 changed files with 36 additions and 2 deletions

View File

@ -22,6 +22,7 @@
<body>
<release version="3.2" date="TBA" description="Next release">
<action issue="LANG-928" type="fix">OctalUnescaper has bugs when parsing octals starting with a zero</action>
<action issue="LANG-905" type="fix">EqualsBuilder returns true when comparing arrays, even when the elements are different</action>
<action issue="LANG-774" type="add" due-to="Erhan Bagdemir">Added isStarted, isSuspended and isStopped to StopWatch</action>
<action issue="LANG-917" type="fix" due-to="Arne Burmeister">Fixed exception when combining custom and choice format in ExtendedMessageFormat</action>

View File

@ -50,6 +50,10 @@ public int translate(final CharSequence input, final int index, final Writer out
end--; // rollback
break;
}
// only 3 characters applicable for Octal
if (end - start >= 3) {
break;
}
}
out.write( Integer.parseInt(input.subSequence(start, end).toString(), 8) );

View File

@ -44,15 +44,44 @@ public void testBetween() {
input = "\\378 and";
result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\378 and", result);
assertEquals("Failed to unescape octal characters via the between method", "\37" + "8 and", result);
input = "\\378";
result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\378", result);
assertEquals("Failed to unescape octal characters via the between method", "\37" + "8", result);
input = "\\1";
result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\1", result);
input = "\\036";
result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\036", result);
input = "\\0365";
result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\036" + "5", result);
input = "\\003";
result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\003", result);
input = "\\0003";
result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\000" + "3", result);
}
@Test
public void testOutOfRange() {
final OctalUnescaper oue = new OctalUnescaper();
String input = "\\999";
try {
String result = oue.translate(input);
fail("NumberFormatException was expected for input: " + input);
} catch(NumberFormatException nfe) {
// expected
}
}
}