[
https://issues.apache.org/jira/browse/CAMEL-26312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Work on CAMEL-26312 started by shashank.
----------------------------------------
> camel-core-languages - Simple: a space after a comma is part of the next
> argument of replace, substring, substringBefore, substringAfter,
> substringBetween and contains, so the documented ${replace(" , ')}
> does not replace
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-26312
> URL: https://issues.apache.org/jira/browse/CAMEL-26312
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Reporter: shashank
> Assignee: shashank
> Priority: Major
>
> These functions split their arguments with
> {{StringQuoteHelper.splitSafeQuote(values, ',', false)}}, which keeps the
> white space around a value, also outside its quotes (main aa63c0a4cb94;
> {{replace}} and {{substring}} since 4.7.0, CAMEL-20845, the other four since
> 4.18.0). So a space after the comma becomes part of the next argument:
> {code}
> body: Hello World
> ${replace('o', '0')} -> Hell 0 W 0rld (replaced with
> " 0")
> ${replace('o', '0', ${header.foo})} -> " Hell 0 W 0rld" (the
> expression is " ${header.foo}")
> ${substringBetween(${body}, ' ', 'o')} -> null (looks for " "
> and " o")
> ${contains(${body}, 'hello')} -> false
> ${substring(1, -1)} -> TypeConversionException (" -1")
> {code}
> The examples of the replace function in simple-advanced.adoc ("Replacing
> double and single quotes", in Java, XML and YAML) write a space around the
> comma, and none of them works:
> {code}
> body: say "hi" it's
> ${replace(" , ')} -> say "hi 'it's (expected: say 'hi' it's)
> ${replace(' , ")} -> say "hi" it's (expected: say "hi" it"s)
> ${replace(" , ∅)} -> say "hi ∅it's
> {code}
> The collection functions had the same bug, fixed in 4.23.0 by CAMEL-24969 ("a
> space after a comma no longer leaks into the argument: {{${sort(${body},
> true)}}}, mapAdd, listAdd, ...") with
> {{CollectionFunctionFactory.splitArguments}}; the string functions were not
> in its list. Other functions, such as escape, concat and pad, already take an
> argument without the white space around it; the escape example of the
> functions page writes {{${escape(html, 'Tom & Jerry')}}}.
> *Fix* (proposed): use the {{splitArguments}} helper of CAMEL-24969 for these
> functions too (moved to {{SimpleFunctionHelper}}): split the arguments
> keeping their quotes, then take each one without the white space around it
> and without the quotes around it. The spaces inside quotes are kept ({{'
> '}}), and an argument of only white space is kept as it is, so {{${replace(
> ,-,${header.msg})}}} (pinned by
> {{StringFunctionFactoryTest.testReplaceWithExpression}}) still replaces a
> space. So trimming every argument ({{splitSafeQuote}} with trim=true) is not
> an option: it would make that argument empty. A quote inside an argument
> ({{a'b'c}}, {{'it''s'}}) is now kept instead of removed, as in the collection
> functions (upgrade guide). {{join}} splits the same way ({{${join(&, id=)}}}
> prefixes " id=") and is left for a follow-up, as its separator may be white
> space on purpose.
> *Tests*: {{SimpleTest.testReplaceAllExpressionWithSpacesAroundTheComma}} (the
> three documented examples, and nested expressions),
> {{StringFunctionFactoryTest.testArgumentsWithASpaceAfterTheComma}} (each
> function) and {{StringFunctionFactoryTest.testQuoteInsideAnArgumentIsKept}}
> fail on main and pass with the fix. The language tests of camel-core and the
> whole camel-core suite pass. In apache/camel and camel-kamelets 4.23.0 the
> six functions are written in 97 distinct ways; only the documented examples
> split differently.
> *How it was found*: a readable semantics of Simple written from the
> documentation (Rocq), extracted to an oracle and compared with the language
> on about 4.9 million generated programs (8 200 disagreements of this class).
> The from and to texts that {{StringFunctionFactory}} gives the replace
> function are also checked on the real class files of main and of the fix in a
> JVM model in Rocq (kernel-checked).
> *Affected*: main and every release since 4.7.0 (replace, substring) / 4.18.0
> (substringBefore, substringAfter, substringBetween, contains).
> _Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)