gnodet-bot commented on code in PR #29790:
URL: https://github.com/apache/camel/pull/29790#discussion_r4558235253
##########
core/camel-core-languages/src/main/java/org/apache/camel/language/simple/functions/StringFunctionFactory.java:
##########
@@ -287,18 +289,21 @@ public Expression createFunction(CamelContext
camelContext, String function, int
+ function,
index);
}
- // a comma inside quotes is part of the value, such as
${concat('Hello, ')}
- String[] tokens = StringQuoteHelper.splitSafeQuote(values, ',',
true, true);
- if (tokens.length > 3) {
+ // a comma inside quotes or a nested function is part of the
value, such as ${concat('Hello, ')}
+ String[] tokens = splitArgumentsKeepQuotes(values);
+ if (tokens.length > 3 || tokens[tokens.length == 1 ? 0 : 1] ==
null) {
Review Comment:
💡 **Readability:** The ternary inside the array subscript is hard to parse
at a glance:
```java
tokens[tokens.length == 1 ? 0 : 1] == null
```
A named local variable makes the intent immediately clear — "the mandatory
expression argument is `tokens[1]` when two or more are given, or `tokens[0]`
when only one is given":
```suggestion
if (tokens.length > 3 || tokens[tokens.length == 1 ? 0 : 1] ==
null) {
```
Consider:
```java
int expIdx = tokens.length == 1 ? 0 : 1;
if (tokens.length > 3 || tokens[expIdx] == null) {
```
No semantic change — purely for readability.
##########
core/camel-core/src/test/java/org/apache/camel/language/simple/functions/OtherFunctionArgumentsTest.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.language.simple.functions;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.language.simple.types.SimpleParserException;
+import org.apache.camel.spi.SimpleFunction;
+import org.apache.camel.spi.SimpleLanguageFunctionFactory;
+import org.apache.camel.support.PluginHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The arguments of the functions that did not split their arguments with the
rules of CAMEL-26465: an argument left out
+ * keeps its place, and a comma inside a nested function does not split an
argument.
+ */
+public class OtherFunctionArgumentsTest extends
AbstractSimpleFunctionFactoryTestSupport {
+
+ @BeforeEach
+ public void setUpExchange() {
+ exchange.getIn().setBody("abc");
+ exchange.getIn().setHeader("s", "abcdef");
+ exchange.getIn().setHeader("n", "1234");
+ PluginHelper.getSimpleFunctionRegistry(context).addFunction(new
SimpleFunction() {
+ @Override
+ public String getName() {
+ return "shout";
+ }
+
+ @Override
+ public Object apply(Exchange exchange, Object input) {
+ return input + "!";
+ }
+ });
+ }
+
+ @Override
+ protected SimpleLanguageFunctionFactory createFactory() {
Review Comment:
⚠️ **Mismatch — `createFactory()` returns `MiscFunctionFactory`, but the
class is `OtherFunctionArgumentsTest`:** The test class name suggests it tests
"other" functions broadly, yet `createFactory()` only wires up
`MiscFunctionFactory`. Functions like `concat`, `pad`, `hash` and `range`
(exercised in `testCommaInsideANestedFunction`) live in `StringFunctionFactory`
/ `CollectionFunctionFactory` / `MathFunctionFactory`, not
`MiscFunctionFactory`.
If the base class's `evaluate()` routes through `createFactory()`, those
tests are exercising a different factory than intended and may pass vacuously.
If `evaluate()` bypasses `createFactory()` (e.g. calls `SimpleLanguage.predict`
directly), the return value here is dead code and can be removed to avoid
confusion.
Either way the intent should be clarified — either adjust `createFactory()`
to return the factory that owns the functions under test, or document why the
return value is unused.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]