diff --git a/src/utils/HighlightUtils.ts b/src/utils/HighlightUtils.ts
index 30fc907dc0..222891d283 100644
--- a/src/utils/HighlightUtils.ts
+++ b/src/utils/HighlightUtils.ts
@@ -259,18 +259,19 @@ export class HighlightUtils {
break;
}
- highlighted += _.escape(content.slice(last, start));
- highlighted += `';
+ highlighted += _.escape(content.slice(start, end));
+ highlighted += '';
}
- highlighted += '>';
- highlighted += _.escape(content.slice(start, end));
- highlighted += '';
-
last = end;
}
if (last != maxIndex) {
diff --git a/unitTests/utils/HighlightUtilsTest.ts b/unitTests/utils/HighlightUtilsTest.ts
index 3f0dfa26e0..3f32de7007 100644
--- a/unitTests/utils/HighlightUtilsTest.ts
+++ b/unitTests/utils/HighlightUtilsTest.ts
@@ -10,6 +10,17 @@ export function HighlightUtilsTest() {
const localPath = 'C:\\Programmes\\Ces\\config\\sources\\salesforce';
describe('highlightString', function () {
+ it('should handle highlights that overlap', function () {
+ let highlights: IHighlight[] = [
+ { offset: 9, length: 19 },
+ { offset: 16, length: 12 },
+ { offset: 18, length: 15 }
+ ];
+ let expectedHighlight =
+ 'Lorem ipsum dolor sit amet, ctetur adipisicing elit, sed do eiusmod tempor incididunt ut';
+ expect(HighlightUtils.highlightString(lorem, highlights, null, 'coveo-highlight')).toBe(expectedHighlight);
+ });
+
it('should wrap the passed highlights with tags using the specified class name', function () {
let highlights: IHighlight[] = [
{ offset: 3, length: 5 },