Skip to content

Commit

Permalink
Use indexOf instead of RegExp
Browse files Browse the repository at this point in the history
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and indutny-signal committed Feb 27, 2024
1 parent d545f87 commit dd266d5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ts/types/BodyRange.ts
Expand Up @@ -3,7 +3,7 @@

/* eslint-disable @typescript-eslint/no-namespace */

import { escapeRegExp, isNumber, omit, partition } from 'lodash';
import { isNumber, omit, partition } from 'lodash';

import { SignalService as Proto } from '../protobuf';
import * as log from '../logging/log';
Expand Down Expand Up @@ -572,12 +572,13 @@ export function processBodyRangesForSearchResult({
withNoStartTruncation.length !== cleanedSnippet.length
? TRUNCATION_CHAR.length
: 0;
const rx = new RegExp(escapeRegExp(withNoEndTruncation));
const match = rx.exec(body);

assertDev(Boolean(match), `No match found for "${snippet}" inside "${body}"`);
let startOfSnippet = body.indexOf(withNoEndTruncation);
if (startOfSnippet === -1) {
assertDev(false, `No match found for "${snippet}" inside "${body}"`);
startOfSnippet = 0;
}

const startOfSnippet = match ? match.index : 0;
const endOfSnippet = startOfSnippet + withNoEndTruncation.length;

// We want only the ranges that include the snippet
Expand Down

0 comments on commit dd266d5

Please sign in to comment.