Skip to content

Commit 66937f1

Browse files
authored
fix: hashtags case sentitivity - [CU-869bggh0x] (#256)
1 parent 3bb4ba2 commit 66937f1

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/__tests__/components/ui/TweetContent.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,34 @@ describe('TweetContent', () => {
157157
expect(openSpy).toHaveBeenCalledWith('https://raven.cmp27.space');
158158
expect(onPressMention).toHaveBeenCalledWith('ahmed');
159159
});
160+
161+
it('handles case-insensitive hashtag matching', () => {
162+
const onPressHashtag = jest.fn();
163+
164+
const entities: TweetEntities = {
165+
mentions: [],
166+
hashtags: [
167+
{ hashtag: 'breakingnews', startPosition: 98 },
168+
{ hashtag: 'cybersecurity', startPosition: 178 },
169+
],
170+
};
171+
172+
const text =
173+
'BREAKING: Major tech company confirms a large-scale data breach impacting user accounts worldwide #BreakingNews. Users are advised to update passwords as investigations continue #CyberSecurity #';
174+
175+
const { getByText } = render(
176+
<ThemeProvider>
177+
<TweetContent text={text} entities={entities} onPressHashtag={onPressHashtag} />
178+
</ThemeProvider>
179+
);
180+
181+
const breakingNewsHashtag = getByText('#BreakingNews');
182+
const cyberSecurityHashtag = getByText('#CyberSecurity');
183+
184+
breakingNewsHashtag.props.onPress();
185+
expect(onPressHashtag).toHaveBeenCalledWith('BreakingNews');
186+
187+
cyberSecurityHashtag.props.onPress();
188+
expect(onPressHashtag).toHaveBeenCalledWith('CyberSecurity');
189+
});
160190
});

src/components/ui/TweetContent.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ export default function TweetContent({
5757
const value = e.key;
5858
const len = value.length;
5959

60-
const matchIndex = text.indexOf(value, current);
60+
const matchIndex = text.toLowerCase().indexOf(value.toLowerCase(), current);
6161
if (matchIndex === -1) continue;
6262

6363
if (matchIndex > current)
6464
parts.push({ content: text.slice(current, matchIndex), type: 'text' });
6565

66-
parts.push({ content: text.slice(matchIndex, matchIndex + len), type: e.type, value });
66+
const actualText = text.slice(matchIndex, matchIndex + len);
67+
parts.push({ content: actualText, type: e.type, value: actualText });
6768
current = matchIndex + len;
6869
}
6970

0 commit comments

Comments
 (0)