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 54bff42ff291 CAMEL-24170: Fix remaining HIGH findings from data format
review
54bff42ff291 is described below
commit 54bff42ff291c0028e64ad38c80563c993deb332
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Jul 20 19:49:40 2026 +0200
CAMEL-24170: Fix remaining HIGH findings from data format review
- H2: JacksonXML xmlMapper option missing asRef() in reifier
- H11: Bindy KVP split truncates values containing the separator
- H13: Bindy UnicodeHelper.indexOf off-by-one misses end-of-string
- H15: Protobuf JSON unmarshal uses platform charset instead of UTF-8
- H16: Avro model missing ContentTypeHeaderAware interface
- H17: YAML typeFilter Builder joins class names with '.' instead of ','
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Closes #24946
---
.../dataformat/bindy/BindyKeyValuePairFactory.java | 2 +-
.../camel/dataformat/bindy/UnicodeHelper.java | 2 +-
.../camel/dataformat/bindy/UnicodeHelperTest.java | 15 ++++++
.../fix/BindyKeyValuePairSeparatorInValueTest.java | 53 ++++++++++++++++++++++
.../dataformat/protobuf/ProtobufDataFormat.java | 3 +-
.../camel/model/dataformat/AvroDataFormat.java | 2 +-
.../camel/model/dataformat/YAMLDataFormat.java | 2 +-
.../camel/model/dataformat/YAMLDataFormatTest.java | 48 ++++++++++++++++++++
.../dataformat/JacksonXMLDataFormatReifier.java | 2 +-
9 files changed, 123 insertions(+), 6 deletions(-)
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
index 84acd3dc28ea..aaa42390093d 100644
---
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
+++
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
@@ -141,7 +141,7 @@ public class BindyKeyValuePairFactory extends
BindyAbstractFactory implements Bi
for (String s : data) {
// Get KeyValuePair
- String[] keyValuePair = s.split(getKeyValuePairSeparator());
+ String[] keyValuePair = s.split(getKeyValuePairSeparator(), 2);
// Extract only if value is populated in key:value pair in
incoming message.
if (keyValuePair.length > 1) {
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/UnicodeHelper.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/UnicodeHelper.java
index 2722c563fe52..f7a1313bc0c6 100644
---
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/UnicodeHelper.java
+++
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/UnicodeHelper.java
@@ -124,7 +124,7 @@ public class UnicodeHelper implements Serializable {
final int len = new UnicodeHelper(str, method).length();
- for (int index = fromIndex; index + len < length(); index++) {
+ for (int index = fromIndex; index + len <= length(); index++) {
if (str.equals(input.substring(splitted.get(index),
splitted.get(index + len)))) {
return index;
}
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/UnicodeHelperTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/UnicodeHelperTest.java
index f6f95d643914..0fec5ed4adb4 100644
---
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/UnicodeHelperTest.java
+++
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/UnicodeHelperTest.java
@@ -206,6 +206,21 @@ public class UnicodeHelperTest {
assertEquals(3, lh3.indexOf("m̂", 2));
}
+ @Test
+ public void testIndexOfAtEndOfString() {
+ UnicodeHelper lh = new UnicodeHelper("ab|", Method.CODEPOINTS);
+ assertEquals(2, lh.indexOf("|"));
+
+ UnicodeHelper lh2 = new UnicodeHelper("abc|", Method.CODEPOINTS);
+ assertEquals(3, lh2.indexOf("|"));
+
+ UnicodeHelper lh3 = new UnicodeHelper("|", Method.CODEPOINTS);
+ assertEquals(0, lh3.indexOf("|"));
+
+ UnicodeHelper lh4 = new UnicodeHelper("ab|", Method.GRAPHEME);
+ assertEquals(2, lh4.indexOf("|"));
+ }
+
private static String cps2String(final int... cps) {
final StringBuilder buf = new StringBuilder();
for (int cp : cps) {
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyKeyValuePairSeparatorInValueTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyKeyValuePairSeparatorInValueTest.java
new file mode 100644
index 000000000000..0c38363c85a3
--- /dev/null
+++
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyKeyValuePairSeparatorInValueTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.dataformat.bindy.fix;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.dataformat.bindy.BindyAbstractFactory;
+import org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat;
+import org.apache.camel.dataformat.bindy.model.fix.simple.Order;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class BindyKeyValuePairSeparatorInValueTest {
+
+ @Test
+ public void testValueContainingKeyValueSeparator() throws Exception {
+ BindyKeyValuePairDataFormat dataFormat = new
BindyKeyValuePairDataFormat(Order.class);
+ BindyAbstractFactory factory = dataFormat.getFactory();
+
+ // tag 58 (free text) contains '=' which is also the key-value
separator
+ String message = "8=FIX.4.1" + "" + "58=a=b=c" + "" + "10=220";
+ List<String> data = Arrays.asList(message.split("\\u0001"));
+
+ Map<String, Object> model = new HashMap<>();
+ model.put(Order.class.getName(), new Order());
+
+ CamelContext camelContext = new DefaultCamelContext();
+ factory.bind(camelContext, data, model, 1);
+
+ Order order = (Order) model.get(Order.class.getName());
+ assertEquals("a=b=c", order.getText());
+ }
+}
diff --git
a/components/camel-protobuf/src/main/java/org/apache/camel/dataformat/protobuf/ProtobufDataFormat.java
b/components/camel-protobuf/src/main/java/org/apache/camel/dataformat/protobuf/ProtobufDataFormat.java
index fa4a6934d351..c820885f7d8f 100644
---
a/components/camel-protobuf/src/main/java/org/apache/camel/dataformat/protobuf/ProtobufDataFormat.java
+++
b/components/camel-protobuf/src/main/java/org/apache/camel/dataformat/protobuf/ProtobufDataFormat.java
@@ -182,7 +182,8 @@ public class ProtobufDataFormat extends ServiceSupport
Builder builder = defaultInstance.newBuilderForType();
if (contentTypeFormat.equals(CONTENT_TYPE_FORMAT_JSON)) {
- JsonFormat.parser().ignoringUnknownFields().merge(new
InputStreamReader(inputStream), builder);
+ JsonFormat.parser().ignoringUnknownFields().merge(new
InputStreamReader(inputStream, StandardCharsets.UTF_8),
+ builder);
} else if (contentTypeFormat.equals(CONTENT_TYPE_FORMAT_NATIVE)) {
builder =
defaultInstance.newBuilderForType().mergeFrom(inputStream);
} else {
diff --git
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/AvroDataFormat.java
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/AvroDataFormat.java
index 5f8f76d5afd6..67e07e89db37 100644
---
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/AvroDataFormat.java
+++
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/AvroDataFormat.java
@@ -33,7 +33,7 @@ import org.apache.camel.spi.Metadata;
description = "Serialize and deserialize messages using Apache Avro
binary data format")
@XmlRootElement(name = "avro")
@XmlAccessorType(XmlAccessType.FIELD)
-public class AvroDataFormat extends DataFormatDefinition {
+public class AvroDataFormat extends DataFormatDefinition implements
ContentTypeHeaderAware {
@XmlTransient
private Class<?> unmarshalType;
diff --git
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLDataFormat.java
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLDataFormat.java
index 747f871665f9..9eaee1321a64 100644
---
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLDataFormat.java
+++
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLDataFormat.java
@@ -408,7 +408,7 @@ public class YAMLDataFormat extends DataFormatDefinition {
* Set the types SnakeYAML is allowed to un-marshall.
*/
public Builder typeFilter(Class<?>... typeFilter) {
- StringJoiner sj = new StringJoiner(".");
+ StringJoiner sj = new StringJoiner(",");
for (Class<?> c : typeFilter) {
sj.add(c.getName());
}
diff --git
a/core/camel-core-model/src/test/java/org/apache/camel/model/dataformat/YAMLDataFormatTest.java
b/core/camel-core-model/src/test/java/org/apache/camel/model/dataformat/YAMLDataFormatTest.java
new file mode 100644
index 000000000000..2ededfb0e807
--- /dev/null
+++
b/core/camel-core-model/src/test/java/org/apache/camel/model/dataformat/YAMLDataFormatTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.model.dataformat;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class YAMLDataFormatTest {
+
+ @Test
+ public void testTypeFilterWithMultipleClasses() {
+ YAMLDataFormat df = new YAMLDataFormat.Builder()
+ .typeFilter(String.class, Integer.class)
+ .end();
+ assertEquals("java.lang.String,java.lang.Integer", df.getTypeFilter());
+ }
+
+ @Test
+ public void testTypeFilterWithSingleClass() {
+ YAMLDataFormat df = new YAMLDataFormat.Builder()
+ .typeFilter(String.class)
+ .end();
+ assertEquals("java.lang.String", df.getTypeFilter());
+ }
+
+ @Test
+ public void testTypeFilterWithString() {
+ YAMLDataFormat df = new YAMLDataFormat.Builder()
+ .typeFilter("com.example.Foo,com.example.Bar")
+ .end();
+ assertEquals("com.example.Foo,com.example.Bar", df.getTypeFilter());
+ }
+}
diff --git
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JacksonXMLDataFormatReifier.java
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JacksonXMLDataFormatReifier.java
index 96f16f23489e..1f23bc9ea73b 100644
---
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JacksonXMLDataFormatReifier.java
+++
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JacksonXMLDataFormatReifier.java
@@ -30,7 +30,7 @@ public class JacksonXMLDataFormatReifier extends
DataFormatReifier<JacksonXMLDat
@Override
protected void prepareDataFormatConfig(Map<String, Object> properties) {
- properties.put("xmlMapper", definition.getXmlMapper());
+ properties.put("xmlMapper", asRef(definition.getXmlMapper()));
properties.put("unmarshalType", or(definition.getUnmarshalType(),
definition.getUnmarshalTypeName()));
properties.put("jsonView", or(definition.getJsonView(),
definition.getJsonViewTypeName()));
properties.put("prettyPrint", definition.getPrettyPrint());