This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-4.10.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push: new e6002502d41 CAMEL-22068: camel-bindy - Fix the escaped double quotes in CSV data (#18066) e6002502d41 is described below commit e6002502d413ac894de0f4c306f0b8e3cfdf2d5b Author: Zheng Feng <zh.f...@gmail.com> AuthorDate: Thu May 15 19:40:52 2025 +0800 CAMEL-22068: camel-bindy - Fix the escaped double quotes in CSV data (#18066) --- .../dataformat/bindy/csv/BindyCsvDataFormat.java | 19 +++++++++++++++++-- .../BindySimpleCsvFunctionWithExternalMethodTest.java | 7 ++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java index 7da1d67e6ea..7c45d62eb52 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java @@ -331,8 +331,23 @@ public class BindyCsvDataFormat extends BindyAbstractDataFormat { // "not empty"+quote if (s.endsWith(quote)) { - cutEnd = true; - canClose = true; + boolean escaped = false; + if (quote.equals("\"")) { + for (int i = s.length() - 2; i > 0; i--) { + char ch = s.charAt(i); + if (ch == '"' && canStart) { + escaped = !escaped; + } else if (ch == '\\') { + continue; + } else { + break; + } + } + } + if (!escaped) { + cutEnd = true; + canClose = true; + } } // optimize to only substring once diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvFunctionWithExternalMethodTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvFunctionWithExternalMethodTest.java index 16e8da47a0e..2e5b10a1439 100644 --- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvFunctionWithExternalMethodTest.java +++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvFunctionWithExternalMethodTest.java @@ -54,11 +54,12 @@ public class BindySimpleCsvFunctionWithExternalMethodTest extends CamelTestSuppo mockEndPointMarshal1.expectedMessageCount(1); mockEndPointMarshal1 - .expectedBodiesReceived("\"123\",\"\"\"foo\"\"\",\"10\"" + ConverterUtils.getStringCarriageReturn("WINDOWS")); + .expectedBodiesReceived( + "\"123\",\"\"\"foo\"\",abc\",\"10\"" + ConverterUtils.getStringCarriageReturn("WINDOWS")); BindyCsvRowFormat7621 body = new BindyCsvRowFormat7621(); body.setFirstField("123"); - body.setSecondField("\"foo\""); + body.setSecondField("\"foo\",abc"); body.setNumber(new BigDecimal(10)); template.sendBody("direct:startMarshal1", body); @@ -68,7 +69,7 @@ public class BindySimpleCsvFunctionWithExternalMethodTest extends CamelTestSuppo = mockEndPointUnMarshal1.getReceivedExchanges().get(0).getIn().getBody(BindyCsvRowFormat7621.class); assertEquals("123", model.getFirstField()); - assertEquals("\"bar\"", model.getSecondField()); + assertEquals("\"bar\",abc", model.getSecondField()); assertEquals(new BigDecimal(10), model.getNumber()); }