Skip to content

Commit bd4aa47

Browse files
committed
Don't return broken matches when requested unsigned
Change-Id: I29cddd0e4efa783d6ca06eed3e2b8ecc69f2f9f9
1 parent 3f29812 commit bd4aa47

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

Changes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
0.64.0 2025-03-28
1+
0.64.0 2025-04-30
22
- [feature] Support signed matchids to prevent consecutive
33
positional requests (diewald)
4+
- [feature] Add support for krill.index.textSize.max (kupietz)
45

56
0.63.3 2024-12-15
67
- [performance] Improve short circuit on count=0 and

src/main/java/de/ids_mannheim/korap/response/Match.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ public Match (int maxTokenMatchSize, PositionsToOffset pto,
208208
public Match (int maxTokenMatchSize, String idString, boolean includeHighlights) {
209209
MatchIdentifier id = new MatchIdentifier(idString);
210210

211+
if (id.getTextSigle() == "" && id.getDocID() == "")
212+
return;
213+
211214
if (id.getStartPos() > -1) {
212215
this.mirrorIdentifier = id.toString();
213216

src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ else if (id.contains("!") || !id.contains("_")) {
105105
// No signature returned
106106
if (hmacStr == null) {
107107
this.textSigle = "";
108+
this.docID = "";
108109
return;
109110
};
110111

@@ -115,6 +116,7 @@ else if (id.contains("!") || !id.contains("_")) {
115116

116117
if (!MessageDigest.isEqual(hmacBytes, hmacVerify)) {
117118
this.textSigle = "";
119+
this.docID = "";
118120
return;
119121
};
120122
};

src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,37 @@ public void indexExample4 () throws IOException, QueryException {
387387
km.getSnippetHTML());
388388
};
389389

390+
@Test
391+
public void indexExampleSign () throws IOException, QueryException {
392+
393+
MatchIdentifier.initMac("tree");
394+
395+
396+
KrillIndex ki = new KrillIndex();
397+
ki.addDoc(createSimpleFieldDoc());
398+
ki.commit();
399+
400+
Match km = ki.getMatchInfo("match-c1!d1-p7-9(4)8-8(2)7-8", "tokens",
401+
null, null, false, false);
402+
403+
JsonNode res = mapper.readTree(km.toJsonString());
404+
assertEquals("Invalid match identifier", res.at("/errors/0/1").asText());
405+
assertEquals("", res.at("/matchID").asText());
406+
assertEquals("", res.at("/fields/0/key").asText());
407+
408+
409+
km = ki.getMatchInfo("match-c1!d1-p7-9(2)7-8(1)8-8x_07WRwmjA5EigwG8wYcURhnz_WkL9cepvU96hC2mp6SE", "tokens",
410+
null, null, false, false);
411+
412+
res = mapper.readTree(km.toJsonString());
413+
assertEquals("", res.at("/errors/0/1").asText());
414+
assertEquals("match-c1!d1-p7-9(2)7-8(1)8-8x_07WRwmjA5EigwG8wYcURhnz_WkL9cepvU96hC2mp6SE", res.at("/matchID").asText());
415+
assertEquals("ID", res.at("/fields/0/key").asText());
416+
417+
MatchIdentifier.initMac("");
418+
};
419+
420+
390421

391422
@Test
392423
public void indexNewStructure () throws IOException, QueryException {

0 commit comments

Comments
 (0)