gnodet-bot commented on code in PR #30685:
URL: https://github.com/apache/camel/pull/30685#discussion_r4671395960


##########
components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java:
##########
@@ -221,6 +232,87 @@ public void testHtmlParseWithEmptyTitle() {
         assertEmptyTitle(html);
     }
 
+    @Test
+    public void testHtmlParseWithInvalidXmlCharactersInMetadata() {
+        String input
+                = "<html><head><title>Test</title><meta name=\"description\" 
content=\"Invalid\u0000Meta\"/></head><body><p>Hello World</p></body></html>";
+        String html = template.requestBody("direct:html", 
input.getBytes(StandardCharsets.UTF_8), String.class);
+        assertThat(html, containsString("<title>Test</title>"));
+        assertThat(html, containsString("Invalid\uFFFDMeta"));
+        assertThat(html, containsString("Hello World"));
+        assertThat(html, not(containsString("\0")));
+    }

Review Comment:
   This test does not exercise `SafeContentHandler`. Tika routes HTML input 
through JSoup's parser, whose HTML5 tokenizer replaces `U+0000` → `U+FFFD` in 
`TokeniserState` before any SAX events are emitted — so the null chars are 
sanitized before `SafeContentHandler` is ever invoked. This test would pass 
identically without the fix.



##########
components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java:
##########
@@ -221,6 +232,87 @@ public void testHtmlParseWithEmptyTitle() {
         assertEmptyTitle(html);
     }
 
+    @Test
+    public void testHtmlParseWithInvalidXmlCharactersInMetadata() {
+        String input
+                = "<html><head><title>Test</title><meta name=\"description\" 
content=\"Invalid\u0000Meta\"/></head><body><p>Hello World</p></body></html>";
+        String html = template.requestBody("direct:html", 
input.getBytes(StandardCharsets.UTF_8), String.class);
+        assertThat(html, containsString("<title>Test</title>"));
+        assertThat(html, containsString("Invalid\uFFFDMeta"));
+        assertThat(html, containsString("Hello World"));
+        assertThat(html, not(containsString("\0")));
+    }
+
+    @Test
+    public void testXmlParseWithInvalidXmlCharactersInMetadata() {
+        String input
+                = "<html><head><title>Test</title><meta name=\"description\" 
content=\"Invalid\u0000Meta\"/></head><body><p>Hello World</p></body></html>";
+        String xml = template.requestBody("direct:xml", 
input.getBytes(StandardCharsets.UTF_8), String.class);
+        assertThat(xml, containsString("<title>Test</title>"));
+        assertThat(xml, containsString("Invalid\uFFFDMeta"));
+        assertThat(xml, containsString("Hello World"));
+        assertThat(xml, not(containsString("\0")));
+    }

Review Comment:
   Same issue as the HTML test above: the XML output format still uses JSoup's 
HTML tokenizer for the HTML input, so `U+0000` is replaced before reaching 
`SafeContentHandler`. Consider using a document type parsed via a non-JSoup 
parser (e.g. plain text or XML) or use the 
`createParserWithInvalidCharacters()` approach from the custom-parser tests 
below.



-- 
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]

Reply via email to