Skip to content

Commit

Permalink
fixed escapable characters for rename
Browse files Browse the repository at this point in the history
  • Loading branch information
reonZ committed Dec 8, 2022
1 parent 41fd83b commit 3492a5e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { replaceHTMLText } from './@utils/jquery'
import { getName, playersSeeName } from './api'
import { thirdPartyChatParse } from './third'

const ESCAPE = /(["'\(\)\[\]])/gm

export function renderChatMessage(message: ChatMessage, html: JQuery) {
if (message.blind) return

const isGM = game.user.isGM
const speaker = message.speaker
const actor = ChatMessage.getSpeakerActor(speaker)
const playersCanSee = !!actor && (actor.hasPlayerOwner || playersSeeName(actor))
const playersCanSee = !actor || actor.hasPlayerOwner || playersSeeName(actor)

if (actor && !playersCanSee) {
changeNames(message, actor, html)
Expand All @@ -29,7 +31,7 @@ export function renderChatMessage(message: ChatMessage, html: JQuery) {

function changeNames(message: ChatMessage, actor: Actor, html: JQuery) {
const speaker = message.speaker
const names = new Set()
const names: Set<string> = new Set()

if (speaker.alias) names.add(speaker.alias)
if (actor.name) names.add(actor.name)
Expand All @@ -42,7 +44,7 @@ function changeNames(message: ChatMessage, actor: Actor, html: JQuery) {

if (!names.size) return

const joined = Array.from(names).join('|')
const joined = RegExp.escape(Array.from(names).join('|'))
const regexp = new RegExp(`(${joined})`, 'gmi')
const renamed = getName(actor)
const replacement = game.user.isGM ? `<span class="anonymous-replaced" title="${renamed}">$1</span>` : renamed
Expand Down

0 comments on commit 3492a5e

Please sign in to comment.