This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.11.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.11.x by this push: new f0920bb [CAMEL-16922] check string length before removing quotes (#6046) f0920bb is described below commit f0920bb8ecb52a5e77d24b2efb29ac21b8694bf6 Author: fizzet <jen...@gmx.net> 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());