chibenwa commented on code in PR #2583:
URL: https://github.com/apache/james-project/pull/2583#discussion_r1922123038


##########
mailbox/api/src/test/java/org/apache/james/mailbox/searchhighligt/SearchHighLighterContract.java:
##########
@@ -532,4 +532,43 @@ default void shouldHighLightBodyWhenHTMLBodyMatched() 
throws Exception {
             
softly.assertThat(searchSnippets.getFirst().highlightedBody().get()).contains("<mark>barcamp</mark>");
         });
     }
+
+    @Test
+    default void highlightSearchShouldShortenGreaterThanCharacters() throws 
Exception {
+        MailboxSession session = session(USERNAME1);
+
+        // Given m1,m2 with m1 has body containing the searched word (contentA)
+        ComposedMessageId m1 = appendMessage(MessageManager.AppendCommand.from(
+                Message.Builder.of()
+                    .setTo("to@james.local")
+                    .setSubject("Hallo, Thx Matthieu for your help")
+                    .setBody("Start \n>>>>>>>>>> append contentA to > inbox 
\n>>>>>> End",
+                        StandardCharsets.UTF_8)),
+            session).getId();
+
+        ComposedMessageId m2 = appendMessage(MessageManager.AppendCommand.from(
+                Message.Builder.of()
+                    .setTo("to@james.local")
+                    .setSubject("Hallo, Thx Alex for your help")
+                    .setBody("append contentB to inbox", 
StandardCharsets.UTF_8)),
+            session).getId();
+
+        verifyMessageWasIndexed(2);
+
+        // When searching for the word (contentA) in the body
+        MultimailboxesSearchQuery multiMailboxSearch = 
MultimailboxesSearchQuery.from(SearchQuery.of(
+                SearchQuery.bodyContains("contentA")))
+            .inMailboxes(List.of(m1.getMailboxId(), m2.getMailboxId()))
+            .build();
+
+        // Then highlightSearch should return the SearchSnippet with the 
highlightedBody containing the word (contentA)
+        List<SearchSnippet> searchSnippets = 
Flux.from(testee().highlightSearch(List.of(m1.getMessageId(), 
m2.getMessageId()), multiMailboxSearch, session))
+            .collectList()
+            .block();
+        assertThat(searchSnippets).hasSize(1);
+        assertSoftly(softly -> {
+            
softly.assertThat(searchSnippets.getFirst().messageId()).isEqualTo(m1.getMessageId());
+            
softly.assertThat(searchSnippets.getFirst().highlightedBody().get()).isEqualTo("Start
 \n append <mark>contentA</mark> to > inbox \n End");

Review Comment:
   shouldn't this lone `>` be html encoded?
   
   Otherwise text plain stuff may be leveraged for HTML injections...



-- 
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: notifications-unsubscr...@james.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to