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 1fea3fcdd047 CAMEL-27304: camel-tika - test that html and xml output
replace a NUL in the title (#30752)
1fea3fcdd047 is described below
commit 1fea3fcdd047e06b014661d13ba9dcbff50fc52b
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Nov 24 21:12:49 2026 +0100
CAMEL-27304: camel-tika - test that html and xml output replace a NUL in
the title (#30752)
CAMEL-27201 (a duplicate of CAMEL-27304) reported that html and xml output
fail on a NUL in the document title. The failure came from the empty title
written by ExpandedTitleContentHandler, fixed by CAMEL-27304. A NUL that is
really in the title is replaced with U+FFFD by Tika's XHTMLContentHandler.
Add tests for both output formats.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../apache/camel/component/tika/TikaParseTest.java | 25 ++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git
a/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java
b/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java
index 60a12af7ec72..f76115bf6cdb 100644
---
a/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java
+++
b/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java
@@ -63,6 +63,9 @@ public class TikaParseTest extends CamelTestSupport {
private static final String HTML_WITHOUT_TITLE =
"<html><head></head><body><p>" + TEXT + "</p></body></html>";
private static final String HTML_WITH_EMPTY_TITLE
= "<html><head><title></title></head><body><p>" + TEXT +
"</p></body></html>";
+ // NUL is not allowed in XML: Tika replaces it with U+FFFD, so the html
and xml output do not fail (CAMEL-27201)
+ private static final String HTML_WITH_NUL_IN_TITLE
+ = "<html><head><title>Te\u0000st</title></head><body><p>" + TEXT +
"</p></body></html>";
@EndpointInject("mock:result")
protected MockEndpoint resultEndpoint;
@@ -230,6 +233,27 @@ public class TikaParseTest extends CamelTestSupport {
assertThat(html, containsString(TEXT));
}
+ @Test
+ public void testHtmlParseNulInTitle() {
+ String html = template.requestBody("direct:html",
HTML_WITH_NUL_IN_TITLE, String.class);
+ assertThat(html, containsString("<title>Te\uFFFDst</title>"));
+ assertNoNul(html);
+ assertThat(html, containsString(TEXT));
+ }
+
+ @Test
+ public void testXmlParseNulInTitle() {
+ String xml = template.requestBody("direct:xml",
HTML_WITH_NUL_IN_TITLE, String.class);
+ assertThat(xml, containsString("<title>Te\uFFFDst</title>"));
+ assertNoNul(xml);
+ assertThat(xml, containsString(TEXT));
+ }
+
+ private static void assertNoNul(String output) {
+ assertThat(output, not(containsString("\0")));
+ assertThat(output, not(containsString("�")));
+ }
+
@Test
public void testParseBodyNotStream() {
Exception e = assertThrows(CamelExecutionException.class,
@@ -276,6 +300,7 @@ public class TikaParseTest extends CamelTestSupport {
from("direct:start4").to("tika:parse?tikaParseOutputEncoding="
+ StandardCharsets.UTF_16.name())
.to("mock:result");
from("direct:html").to("tika:parse?tikaParseOutputFormat=html");
+ from("direct:xml").to("tika:parse?tikaParseOutputFormat=xml");
from("direct:start5")
.to("tika:parse?tikaParseOutputFormat=text&tikaParseOutputEncoding=" +
StandardCharsets.UTF_16.name())
.to("mock:result");