File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -205,12 +205,21 @@ describe("special characters", () => {
205205} ) ;
206206
207207describe ( "empty example" , ( ) => {
208+ // even though it is not expected we should make sure it won't break
208209 it ( "should not break when text is null" , ( ) => {
209210 const searchTerm = "C" ;
210211 const highlighter = new Highlight ( ) ;
211212
212- // even though it is not expected we should make sure it won't break
213213 // @ts -expect-error
214214 assert . strictEqual ( highlighter . highlight ( null , searchTerm ) . HTML , "" ) ;
215215 } ) ;
216+ it ( "should not break when search term is null" , ( ) => {
217+ const highlighter = new Highlight ( ) ;
218+
219+ assert . strictEqual (
220+ // @ts -expect-error
221+ highlighter . highlight ( null , null ) . HTML ,
222+ '<mark class="orama-highlight"></mark>'
223+ ) ;
224+ } ) ;
216225} ) ;
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ export class Highlight {
2727 }
2828
2929 public highlight ( text : string , searchTerm : string ) : Highlight {
30- this . _searchTerm = searchTerm ;
30+ this . _searchTerm = searchTerm ?? "" ;
3131 this . _originalText = text ?? "" ;
3232
3333 const caseSensitive =
@@ -38,7 +38,7 @@ export class Highlight {
3838 const regexFlags = caseSensitive ? "g" : "gi" ;
3939 const boundary = wholeWords ? "\\b" : "" ;
4040 const searchTerms = this . escapeRegExp (
41- caseSensitive ? searchTerm : searchTerm . toLowerCase ( )
41+ caseSensitive ? this . _searchTerm : this . _searchTerm . toLowerCase ( )
4242 )
4343 . trim ( )
4444 . split ( / \s + / )
You can’t perform that action at this time.
0 commit comments