This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new acad09d [CAMEL-16922] check string length before removing quotes
(#6046)
acad09d is described below
commit acad09dcaee26ecf01bc213729f48f1f99094675
Author: fizzet <[email protected]>
AuthorDate: Fri Sep 3 17:41:30 2021 +0200
[CAMEL-16922] check string length before removing quotes (#6046)
---
.../src/main/java/org/apache/camel/util/StringHelper.java | 3 +++
.../src/test/java/org/apache/camel/util/StringHelperTest.java | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git
a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
index 313bb500..0c9ab54 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
@@ -146,6 +146,9 @@ public final class StringHelper {
}
String copy = s.trim();
+ if (copy.length() < 2) {
+ return s;
+ }
if (copy.startsWith("'") && copy.endsWith("'")) {
return copy.substring(1, copy.length() - 1);
}
diff --git
a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
index e95c18b..a9849bd 100644
--- a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
+++ b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
@@ -125,6 +125,15 @@ public class StringHelperTest {
}
@Test
+ public void testRemoveLeadingAndEndingQuotes() throws Exception {
+ assertEquals("abc", removeLeadingAndEndingQuotes("'abc'"));
+ assertEquals("abc", removeLeadingAndEndingQuotes("\"abc\""));
+ assertEquals("a'b'c", removeLeadingAndEndingQuotes("a'b'c"));
+ assertEquals("'b'c", removeLeadingAndEndingQuotes("'b'c"));
+ assertEquals("", removeLeadingAndEndingQuotes("''"));
+ assertEquals("'", removeLeadingAndEndingQuotes("'"));
+ }
+
public void testSplitOnCharacterAsList() throws Exception {
List<String> list = splitOnCharacterAsList("foo", ',', 1);
assertEquals(1, list.size());