web: Fix usage of .replace with variable replacement.

String.prototype.replace and String.prototype.replaceAll interpret
certain sequences such as $$ within a string provided as the
replacement argument.  Avoid this interpretation by providing a
function.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-04-04 16:48:15 -07:00 committed by Tim Abbott
parent 44c4b93f6e
commit 64cabae46d
2 changed files with 2 additions and 2 deletions

View File

@ -781,7 +781,7 @@ export function get_external_account_link(field) {
} else {
field_url_pattern = realm.realm_default_external_accounts[field_subtype].url_pattern;
}
return field_url_pattern.replace("%(username)s", field.value);
return field_url_pattern.replace("%(username)s", () => field.value);
}
export function set_up() {

View File

@ -1188,7 +1188,7 @@ Parser.prototype.parse = function(src) {
if (!safe) {
html = escape(html);
}
output = output.replace('<p>' + key + '</p>', html)
output = output.replace('<p>' + key + '</p>', () => html)
}
return output;
};