Correctly calculate endpage

Change-Id: I8d0c07da122c282fda5e9361b8b8c26d22a75d1c
diff --git a/Changes b/Changes
index b0448c8..b1935da 100644
--- a/Changes
+++ b/Changes
@@ -5,6 +5,7 @@
     - [bugfix] Prevent showing empty elements and opening tags past primary data
       (diewald).
     - [cleanup] Cleanup test generated directories after run (diewald)
+    - [bugfix] Correctly calculate endpage (diewald)
 
 0.62.6 2024-06-13
     - [feature] Make match expansion configurable (close #150, margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/response/Match.java b/src/main/java/de/ids_mannheim/korap/response/Match.java
index 76be86e..5340e2f 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -1106,7 +1106,7 @@
                 if (pagebreaks.get(i)[0] <= this.getStartPos()) {
                     this.startPage = pagebreaks.get(i)[1];
                 } else {
-                    i++;
+                    // i++;
                     break;
                 };
             };
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestPagebreakIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestPagebreakIndex.java
index fc612ac..f27f21b 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestPagebreakIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestPagebreakIndex.java
@@ -82,12 +82,16 @@
                      kr.getMatch(2).getSnippetHTML());
         assertEquals("{%528}abcab[[{%529}c]]ab{%530}ac",
                      kr.getMatch(2).getSnippetBrackets());
-		assertEquals(-1, kr.getMatch(2).getEndPage()); // Debatable
+		assertEquals(-1, kr.getMatch(2).getEndPage());
 
         assertEquals(9, kr.getMatch(3).getStartPos());
 		assertEquals(10, kr.getMatch(3).getEndPos());
 		assertEquals(530, kr.getMatch(3).getStartPage());
 		assertEquals(-1, kr.getMatch(3).getEndPage());
+        assertEquals("<span class=\"context-left\"><span class=\"more\"></span>ab<span class=\"pb\" data-after=\"529\"></span>cab<span class=\"pb\" data-after=\"530\"></span>a</span><span class=\"match\"><mark>c</mark></span><span class=\"context-right\"></span>",
+                     kr.getMatch(3).getSnippetHTML());
+        assertEquals("... ab{%529}cab{%530}a[[c]]",
+                     kr.getMatch(3).getSnippetBrackets());
     };
 
     @Test
@@ -147,7 +151,7 @@
 		kr = ki.search(sq, (short) 10);
 		
 		assertEquals(528, kr.getMatch(0).getStartPage());
-		assertEquals(-1, kr.getMatch(0).getEndPage());
+		assertEquals(529, kr.getMatch(0).getEndPage());
 
 		assertEquals(
 			"snippetHTML",