From dd266d5d25997eb0686e924b71aa566ade089c7f Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:58:11 -0600 Subject: [PATCH] Use indexOf instead of RegExp Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> --- ts/types/BodyRange.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ts/types/BodyRange.ts b/ts/types/BodyRange.ts index b890ad61b68..069c20ea93e 100644 --- a/ts/types/BodyRange.ts +++ b/ts/types/BodyRange.ts @@ -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'; @@ -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