Giter VIP home page Giter VIP logo

Comments (4)

xcurry avatar xcurry commented on September 17, 2024

The problem can also be reproduced by changing the caseInsensitive test case to:

@Test
public void caseInsensitive() {
    Trie trie = new Trie().caseInsensitive().onlyWholeWords();
    trie.addKeyword("turning");
    trie.addKeyword("once");
    trie.addKeyword("again");
    trie.addKeyword("börkü");
    Collection<Emit> emits = trie.parseText("TurninG OnCe AgAiN BÖRKÜ");
    assertEquals(4, emits.size()); // Match must not be made
    Iterator<Emit> it = emits.iterator();
    checkEmit(it.next(), 0, 6, "turning");
    checkEmit(it.next(), 8, 11, "once");
    checkEmit(it.next(), 13, 17, "again");
    checkEmit(it.next(), 19, 23, "börkü");
}

Tests in error:
caseInsensitive(org.ahocorasick.trie.TrieTest): String index out of range: 24

from aho-corasick.

xcurry avatar xcurry commented on September 17, 2024

diff --git a/src/main/java/org/ahocorasick/trie/Trie.java b/src/main/java/org/ahocorasick/trie/Trie.java
index 0d28c9b..f25490d 100644
--- a/src/main/java/org/ahocorasick/trie/Trie.java
+++ b/src/main/java/org/ahocorasick/trie/Trie.java
@@ -117,7 +117,7 @@ public class Trie {
for (Emit emit : collectedEmits) {
if ((emit.getStart() == 0 ||
!Character.isAlphabetic(searchText.charAt(emit.getStart() - 1))) &&

  •            (emit.getEnd() == size ||
    
  •            (emit.getEnd() == size - 1 ||
              !Character.isAlphabetic(searchText.charAt(emit.getEnd() + 1)))) {
             continue;
         }
    

(I think :))

from aho-corasick.

robert-bor avatar robert-bor commented on September 17, 2024

Great, I've reproduced the error thanks to your finding. Looking into it right now. Thanks!

from aho-corasick.

robert-bor avatar robert-bor commented on September 17, 2024

The error was in this boundary check:

            if ((emit.getStart() == 0 ||
                 !Character.isAlphabetic(searchText.charAt(emit.getStart() - 1))) &&
                (emit.getEnd() == size ||
                 !Character.isAlphabetic(searchText.charAt(emit.getEnd() + 1)))) {
                continue;
            }

The emit.getEnd() == size does not do a proper boundary check. I've changed it to:

                (emit.getEnd() + 1 == size ||

Will commit and release a new version.

Thanks again for submitting your issue!

from aho-corasick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.