You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/08/10 23:42:30 UTC
[lang] LANG-1162 StringUtils#equals fails with Index OOBE on
non-Strings with identical leading prefix
Repository: commons-lang
Updated Branches:
refs/heads/master fad946a1d -> 6849dfc8a
LANG-1162 StringUtils#equals fails with Index OOBE on non-Strings with
identical leading prefix
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/6849dfc8
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/6849dfc8
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/6849dfc8
Branch: refs/heads/master
Commit: 6849dfc8a660bf8c95354520a2fa1283c9b3aa43
Parents: fad946a
Author: Sebb <se...@apache.org>
Authored: Mon Aug 10 22:42:21 2015 +0100
Committer: Sebb <se...@apache.org>
Committed: Mon Aug 10 22:42:21 2015 +0100
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/lang3/StringUtils.java | 5 ++++-
.../org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java | 2 +-
3 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/6849dfc8/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index fa53e12..65e0b3d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -61,6 +61,7 @@
<action issue="LANG-1111" type="fix" dev="chas">Fix FindBugs warnings in DurationFormatUtils</action>
<action issue="LANG-1074" type="add" dev="djones" due-to="Haiyang Li">Add a method to ArrayUtils for removing all occurrences of a given element</action>
<action issue="LANG-1107" type="update" dev="chas">Fix parsing edge cases in FastDateParser</action>
+ <action issue="LANG-1162" type="fix" dev="sebb">StringUtils#equals fails with Index OOBE on non-Strings with identical leading prefix</action>
</release>
<release version="3.4" date="2014-04-06" description="Feature and bugfix release">
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/6849dfc8/src/main/java/org/apache/commons/lang3/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 5f167b9..3f0314f 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -788,10 +788,13 @@ public class StringUtils {
if (cs1 == null || cs2 == null) {
return false;
}
+ if (cs1.length() != cs2.length()) {
+ return false;
+ }
if (cs1 instanceof String && cs2 instanceof String) {
return cs1.equals(cs2);
}
- return CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, Math.max(cs1.length(), cs2.length()));
+ return CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, cs1.length());
}
/**
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/6849dfc8/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
index dc8a513..d2b6418 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
@@ -535,7 +535,7 @@ public class StringUtilsEqualsIndexOfTest {
@Test
public void testEquals() {
- final CharSequence fooCs = FOO, barCs = BAR, foobarCs = FOOBAR;
+ final CharSequence fooCs = new StringBuilder(FOO), barCs = new StringBuilder(BAR), foobarCs = new StringBuilder(FOOBAR);
assertTrue(StringUtils.equals(null, null));
assertTrue(StringUtils.equals(fooCs, fooCs));
assertTrue(StringUtils.equals(fooCs, new StringBuilder(FOO)));