From 42e0c939f3c68ab499c68651c7778ccfd7aca80c Mon Sep 17 00:00:00 2001 From: delthas Date: Sun, 20 Jun 2021 12:54:20 +0200 Subject: [PATCH] lib/linkify: stop using RegExp indices Co-authored-by: Simon Ser Closes: https://todo.sr.ht/~emersion/gamja/90 --- lib/linkify.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/linkify.js b/lib/linkify.js index 61693ab..61f3295 100644 --- a/lib/linkify.js +++ b/lib/linkify.js @@ -2,14 +2,15 @@ import { anchorme, html } from "./index.js"; function linkifyChannel(text, transformChannel) { // Don't match punctuation at the end of the channel name - const channelRegex = /(?:^|\s)(#[^\s]+[^\s.?!…():;,])/gid; + const channelRegex = /(^|\s)(#[^\s]+[^\s.?!…():;,])/gi; let children = []; let match; let last = 0; while ((match = channelRegex.exec(text)) !== null) { - let channel = match[1]; - let [start, end] = match.indices[1]; + let channel = match[2]; + let start = match.index + match[1].length; + let end = start + match[2].length; children.push(text.substring(last, start)); children.push(transformChannel(channel));