Skip to content

Commit 6c27caf

Browse files
authored
Fix/text highlight special char (#1275)
* replace lodash 'lowerString' function with pure js since it's not handling some special characters * added supporting tests
1 parent dd5035d commit 6c27caf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/components/text/__tests__/index.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,29 @@ describe('Text', () => {
3030
const result = uut.getTextPartsByHighlight('Dancing in the Dark', 'da');
3131
expect(result).toEqual(['Da', 'ncing in the ', 'Da', 'rk']);
3232
});
33+
34+
it('Should handle special characters @', () => {
35+
const uut = new Text({});
36+
const result = uut.getTextPartsByHighlight('@ancing in the @ark', '@a');
37+
expect(result).toEqual(['@a', 'ncing in the ', '@a', 'rk']);
38+
});
39+
40+
it('Should handle special characters !', () => {
41+
const uut = new Text({});
42+
const result = uut.getTextPartsByHighlight('!ancing in the !ark', '!a');
43+
expect(result).toEqual(['!a', 'ncing in the ', '!a', 'rk']);
44+
});
45+
46+
it('Should handle special characters starts with @', () => {
47+
const uut = new Text({});
48+
const result = uut.getTextPartsByHighlight('[email protected]', '@wix');
49+
expect(result).toEqual(['uilib', '@wix', '.com']);
50+
});
51+
52+
it('Should handle empty string .', () => {
53+
const uut = new Text({});
54+
const result = uut.getTextPartsByHighlight('@ancing in the @ark', '');
55+
expect(result).toEqual(['@ancing in the @ark']);
56+
});
3357
});
3458
});

src/components/text/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Text extends PureComponent<PropsTypes> {
7070
let highlightIndex;
7171

7272
do {
73-
highlightIndex = _.lowerCase(targetString).indexOf(_.lowerCase(highlightString));
73+
highlightIndex = targetString.toLowerCase().indexOf(highlightString.toLowerCase());
7474
if (highlightIndex !== -1) {
7575
if (highlightIndex > 0) {
7676
textParts.push(targetString.substring(0, highlightIndex));

0 commit comments

Comments
 (0)