Claus Ibsen created CAMEL-24582:
-----------------------------------

             Summary: simple language - add equals/!equals operators for 
literal (non-numeric) string comparison
                 Key: CAMEL-24582
                 URL: https://issues.apache.org/jira/browse/CAMEL-24582
             Project: Camel
          Issue Type: Improvement
          Components: came-core
            Reporter: Claus Ibsen


CAMEL-24580 reported that Simple's == operator always favours numeric 
comparison when both operands are all-digit strings (e.g. "0001" == "001" -> 
true), which loses the leading-zero distinction for identifiers such as bank 
account numbers. That behaviour was confirmed as intentional and long-standing 
(introduced in CAMEL-15587, 2020) and CAMEL-24580 was closed as information 
provided rather than changed, since altering == would be a breaking change for 
existing routes relying on numeric coercion (e.g. comparing zero-padded 
${date:now:HH} values against numeric literals).

As a follow-up, add new binary predicate operators to the Simple language for 
literal/string-only equality that bypass ObjectHelper.typeCoerceEquals numeric 
coercion entirely:

* equals - literal string equality (case-sensitive), analogous to Java's 
String.equals()
* !equals (or notEquals) - negation

Naming rationale: Simple's existing keyword operators already mirror Java 
String method names (contains -> String.contains(), startsWith -> 
String.startsWith(), endsWith -> String.endsWith()), so equals/!equals 
continues that convention rather than borrowing an abbreviated style from other 
languages (e.g. Perl's eq/ne).

Example:
{code:java}
.filter().simple("${header.Account1} equals ${header.Account2}")
{code}
should evaluate "0001" vs "001" as false (plain string comparison), while == on 
the same values continues to return true (existing numeric-favouring behaviour, 
unchanged).

Scope: add EQUALS / NOT_EQUALS to BinaryOperatorType, wire into 
BinaryExpression/PredicateBuilder using plain String equality (no type 
coercion), document in the simple-language.adoc, and add tests alongside the 
existing SimpleOperatorTest cases for ==/=~.

See CAMEL-24580 for the full discussion and rationale.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to