Fix matrix.to link escaping

Properly escapes in replies and with unmatched [].

fixes #854
This commit is contained in:
Nicolas Werner 2022-07-20 13:52:13 +02:00
parent a5dafec147
commit 0ad74590d4
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
5 changed files with 59 additions and 12 deletions

View file

@ -2625,6 +2625,8 @@ TimelineModel::setEdit(const QString &newEdit)
nhlog::ui()->debug("Stored: {}", textBeforeEdit.toStdString());
}
auto quoted = [](QString in) { return in.replace("[", "\\[").replace("]", "\\]"); };
if (edit_ != newEdit) {
auto ev = events.get(newEdit.toStdString(), "");
if (ev && mtx::accessors::sender(*ev) == http::client()->user_id().to_string()) {
@ -2649,7 +2651,7 @@ TimelineModel::setEdit(const QString &newEdit)
for (const auto &[user, link] : reverseNameMapping) {
// TODO(Nico): html unescape the user name
editText.replace(user, QStringLiteral("[%1](%2)").arg(user, link));
editText.replace(user, QStringLiteral("[%1](%2)").arg(quoted(user), link));
}
}