You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/07/02 08:15:53 UTC

[camel] branch main updated: CAMEL-16775: Simple language - Parsing single or double quoted text block should be literal text, and not numeric. This means 01234 is text based and not the integer 1234.

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 c8468fd  CAMEL-16775: Simple language - Parsing single or double quoted text block should be literal text, and not numeric. This means 01234 is text based and not the integer 1234.
c8468fd is described below

commit c8468fd8af3ad14b2f784203fcf6a6fd80fd6bdf
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jul 2 10:15:15 2021 +0200

    CAMEL-16775: Simple language - Parsing single or double quoted text block should be literal text, and not numeric. This means 01234 is text based and not the integer 1234.
---
 .../camel/language/simple/SimplePredicateParser.java      | 15 +++++++++++++--
 .../apache/camel/language/simple/SimpleOperatorTest.java  | 10 ++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
index c928f08..b688974 100644
--- a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
+++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
@@ -290,8 +290,19 @@ public class SimplePredicateParser extends BaseSimpleParser {
         // this can be many things but lets check if this is numeric based, then we can optimize this
         String text = imageToken.getText();
 
-        // lets see if its numeric then we can optimize this
-        boolean numeric = isNumber(text) || isFloatingNumber(text);
+        // is this image from within a quoted block (single or double quoted)
+        boolean quoted = false;
+        if (!nodes.isEmpty()) {
+            SimpleNode last = nodes.get(nodes.size() - 1);
+            quoted = last instanceof SingleQuoteStart || last instanceof DoubleQuoteStart;
+        }
+
+        boolean numeric = false;
+        if (!quoted) {
+            // if the text is not in a quoted block (literal text), then lets see if
+            // its numeric then we can optimize this
+            numeric = isNumber(text) || isFloatingNumber(text);
+        }
         if (numeric) {
             nodes.add(new NumericExpression(imageToken.getToken(), text));
         } else {
diff --git a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
index ed4de94..2b4a2b5 100644
--- a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
@@ -792,6 +792,16 @@ public class SimpleOperatorTest extends LanguageTestSupport {
     }
 
     @Test
+    public void testStartsWithTextAsNumeric() throws Exception {
+        exchange.getIn().setBody("01234");
+        assertPredicate("${in.body} starts with '1234'", false);
+        assertPredicate("${in.body} starts with 1234", false);
+        assertPredicate("${in.body} starts with '01234'", true);
+        assertPredicate("${in.body} starts with \"01234\"", true);
+        assertPredicate("${in.body} starts with 01234", false);
+    }
+
+    @Test
     public void testEndsWith() throws Exception {
         exchange.getIn().setBody("Hello there");
         assertPredicate("${in.body} ends with 'there'", true);