You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2019/08/25 00:14:42 UTC
[commons-lang] branch master updated (e610367 -> 102a6d7)
This is an automated email from the ASF dual-hosted git repository.
kinow pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git.
from e610367 Merge pull request #439 from Stzx/master
new 06aea7e LANG-1475 Fix unwrap StringIndexOutOfBoundsException
new 672025e Supplement changes.xml
new 102a6d7 Merge branch 'pr-441'
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/lang3/StringUtils.java | 16 ++++++++++------
.../java/org/apache/commons/lang3/StringUtilsTest.java | 4 ++++
3 files changed, 15 insertions(+), 6 deletions(-)
[commons-lang] 01/03: LANG-1475 Fix unwrap
StringIndexOutOfBoundsException
Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 06aea7e74cfe4a1578cb76672f1562132090c205
Author: Stzx <si...@hotmail.com>
AuthorDate: Tue Aug 20 11:29:55 2019 +0800
LANG-1475 Fix unwrap StringIndexOutOfBoundsException
When the string length is shorter than two, it should be returned directly without operation.
---
src/main/java/org/apache/commons/lang3/StringUtils.java | 16 ++++++++++------
.../java/org/apache/commons/lang3/StringUtilsTest.java | 4 ++++
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index d3388f7..c0c4635 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -9159,8 +9159,10 @@ public class StringUtils {
* StringUtils.unwrap(null, null) = null
* StringUtils.unwrap(null, '\0') = null
* StringUtils.unwrap(null, '1') = null
+ * StringUtils.unwrap("a", 'a') = "a"
+ * StringUtils.unwrap("aa", 'a') = ""
* StringUtils.unwrap("\'abc\'", '\'') = "abc"
- * StringUtils.unwrap("AABabcBAA", 'A') = "ABabcBA"
+ * StringUtils.unwrap("AABabcBAA", 'A') = "ABabcBA"
* StringUtils.unwrap("A", '#') = "A"
* StringUtils.unwrap("#A", '#') = "#A"
* StringUtils.unwrap("A#", '#') = "A#"
@@ -9175,16 +9177,15 @@ public class StringUtils {
* @since 3.6
*/
public static String unwrap(final String str, final char wrapChar) {
- if (isEmpty(str) || wrapChar == CharUtils.NUL) {
+ if (isEmpty(str) || wrapChar == CharUtils.NUL || str.length() == 1) {
return str;
}
if (str.charAt(0) == wrapChar && str.charAt(str.length() - 1) == wrapChar) {
final int startIndex = 0;
final int endIndex = str.length() - 1;
- if (endIndex != -1) {
- return str.substring(startIndex + 1, endIndex);
- }
+
+ return str.substring(startIndex + 1, endIndex);
}
return str;
@@ -9199,6 +9200,8 @@ public class StringUtils {
* StringUtils.unwrap(null, null) = null
* StringUtils.unwrap(null, "") = null
* StringUtils.unwrap(null, "1") = null
+ * StringUtils.unwrap("a", "a") = "a"
+ * StringUtils.unwrap("aa", "a") = ""
* StringUtils.unwrap("\'abc\'", "\'") = "abc"
* StringUtils.unwrap("\"abc\"", "\"") = "abc"
* StringUtils.unwrap("AABabcBAA", "AA") = "BabcB"
@@ -9216,7 +9219,7 @@ public class StringUtils {
* @since 3.6
*/
public static String unwrap(final String str, final String wrapToken) {
- if (isEmpty(str) || isEmpty(wrapToken)) {
+ if (isEmpty(str) || isEmpty(wrapToken) || str.length() == 1) {
return str;
}
@@ -9224,6 +9227,7 @@ public class StringUtils {
final int startIndex = str.indexOf(wrapToken);
final int endIndex = str.lastIndexOf(wrapToken);
final int wrapLength = wrapToken.length();
+
if (startIndex != -1 && endIndex != -1) {
return str.substring(startIndex + wrapLength, endIndex);
}
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
index 3810a5c..b2e80e6 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
@@ -3073,6 +3073,8 @@ public class StringUtilsTest {
assertNull(StringUtils.unwrap(null, '1'));
assertEquals("abc", StringUtils.unwrap("abc", null));
+ assertEquals("a", StringUtils.unwrap("a", "a"));
+ assertEquals("", StringUtils.unwrap("aa", "a"));
assertEquals("abc", StringUtils.unwrap("\'abc\'", '\''));
assertEquals("abc", StringUtils.unwrap("AabcA", 'A'));
assertEquals("AabcA", StringUtils.unwrap("AAabcAA", 'A'));
@@ -3090,6 +3092,8 @@ public class StringUtilsTest {
assertEquals("abc", StringUtils.unwrap("abc", null));
assertEquals("abc", StringUtils.unwrap("abc", ""));
+ assertEquals("a", StringUtils.unwrap("a", "a"));
+ assertEquals("", StringUtils.unwrap("aa", "a"));
assertEquals("abc", StringUtils.unwrap("\'abc\'", "\'"));
assertEquals("abc", StringUtils.unwrap("\"abc\"", "\""));
assertEquals("abc\"xyz", StringUtils.unwrap("\"abc\"xyz\"", "\""));
[commons-lang] 03/03: Merge branch 'pr-441'
Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 102a6d75650b7578e31bf18b840e0b613e83e439
Merge: e610367 672025e
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Sun Aug 25 12:14:19 2019 +1200
Merge branch 'pr-441'
This closes #441
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/lang3/StringUtils.java | 16 ++++++++++------
.../java/org/apache/commons/lang3/StringUtilsTest.java | 4 ++++
3 files changed, 15 insertions(+), 6 deletions(-)
[commons-lang] 02/03: Supplement changes.xml
Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 672025e0bf266631a2398cf23122cb1c85b56fb5
Author: Stzx <si...@hotmail.com>
AuthorDate: Fri Aug 23 09:53:43 2019 +0800
Supplement changes.xml
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4535fa9..b78dc7a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -61,6 +61,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="update" dev="ggregory">checkstyle.version 8.18 -> 8.23.</action>
<action type="update" dev="ggregory">junit-jupiter 5.5.0 -> 5.5.1.</action>
<action issue="LANG-1477" type="add" dev="jochen">Added Functions.as*, and tests thereof, as suggested by Peter Verhas</action>
+ <action issue="LANG-1475" type="fix" dev="kinow" due-to="stzx">StringUtils.unwrap incorrect throw StringIndexOutOfBoundsException.</action>
</release>
<release version="3.9" date="2019-04-09" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11">