Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the user name contains any regex metacharacters, the ping highlighting does not work. #167

Open
jvert opened this issue Nov 26, 2019 · 1 comment

Comments

@jvert
Copy link

jvert commented Nov 26, 2019

The highlightPing() function uses the user's name directly as a regex when replacing the text with the tag button. This breaks if the user's name contains any regex special characters, e.g. "John Vert (me!)"

quick & simple fix is to change highlightPing to escape the username

html = html.replace(new RegExp(pingText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), __createTag(pingText, userId));

@Wiilf
Copy link

Wiilf commented Jun 2, 2021

We dont need to worry about this with our reggex (PHP). If you handle the next char, spaces and in-between, you can parse past JS and handle it script-side.

Like we do:

// Match found pings
if (preg_match('/@[\w-]+/', $row['content'], $matches)) {
$lookup = $db->query_params('SELECT username, user_id FROM users WHERE username = :username', ['username' => str_replace('@', '', $matches[0])]);
foreach ($lookup as $ping) {
$data['pings'] = [$ping['user_id'] => $ping['username']];
}
} else {
$data['pings'] = [];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants