Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Add guard for text boundary.

Kishore Nallana2a31e6c0b89
diff --git a/src/collection.cpp b/src/collection.cpp
index aed6cb1d..acdb955d 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -2726,7 +2726,7 @@ void Collection::highlight_text(const string& highlight_start_tag, const string&
const std::string& text_token = text.substr(snippet_start_offset, token_len);
matched_tokens.push_back(text_token);
- for(size_t j = 0; j < token_len; j++) {
+ for(size_t j = 0; j < token_len && snippet_start_offset + j < text.size(); j++) {
highlighted_text << text[snippet_start_offset + j];
}