Skip to content

Commit

Permalink
Merge 07b8e43 into f665ba9
Browse files Browse the repository at this point in the history
  • Loading branch information
olamothe committed Mar 20, 2017
2 parents f665ba9 + 07b8e43 commit c9e1b92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/StreamHighlightUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function getRestHighlightsForAllTerms(toHighlight: string, termsToHighlight: { [
let sortedTerms = _.keys(termsToHighlight).sort(termsSorting);
_.each(sortedTerms, (term: string) => {
let termsToIterate = _.compact([term].concat(termsToHighlight[term]).sort(termsSorting));
termsToIterate = _.map(termsToIterate, (term)=> Utils.escapeRegexCharacter(term));
let regex = regexStart;
regex += termsToIterate.join('|') + ')(?=(?:' + nonWordBoundary + '|$)+)';
let indexesFound = StringUtils.getHighlights(toHighlight, new RegExp(regex, opts.regexFlags), term);
Expand Down
7 changes: 7 additions & 0 deletions test/utils/StreamHighlightUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ export function StreamHighlightUtilsTest() {
expect(StreamHighlightUtils.highlightStreamText(toHighlight, terms, {})).toEqual(`${getHighlightResultForTerm('abc', 1, 'abc')}. ${getHighlightResultForTerm('qwerty', 2, 'qwerty')}`);
});

it('should work with regex sensitive character', () => {
var toHighlight = 'Lorem ipsum 9.1.1 dolor *amet*';
let terms: { [originalTerm: string]: string[]; } = {'*amet*': []};
var phrases: { [phrase: string]: { [originalTerm: string]: string[]; } } = {};
expect(StreamHighlightUtils.highlightStreamText(toHighlight, terms, phrases)).toEqual(`Lorem ipsum 9.1.1 dolor ${getHighlightResultForTerm('*amet*', 1, '*amet*')}`);
});

it('should work with number and dash', () => {
var toHighlight = 'Lorem ipsum 9-1-1 dolor sit amet';
let terms: { [originalTerm: string]: string[]; } = { 'lorem': [] };
Expand Down

0 comments on commit c9e1b92

Please sign in to comment.