mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
compose: Fix buggy escaping of LaTeX in quote-and-reply.
Apparently, our use of JavaScript string `.replace()` here was buggy, because replace() has several special escape sequences starting with `$` if they appear in the replacement content string. We can work around this through something of a hack, which is to pass a function as the second argument to replace, which seems cleaner than replacing all $s with $$s. Thanks to Shreya for the report.
This commit is contained in:
@@ -144,4 +144,8 @@ run_test('replace_syntax', () => {
|
|||||||
|
|
||||||
compose_ui.replace_syntax(/b/g, 'B');
|
compose_ui.replace_syntax(/b/g, 'B');
|
||||||
assert.equal($('#compose-textarea').val(), 'ABcaBc');
|
assert.equal($('#compose-textarea').val(), 'ABcaBc');
|
||||||
|
|
||||||
|
// Verify we correctly handle `$`s in the replacement syntax
|
||||||
|
compose_ui.replace_syntax('Bca', '$$\pi$$');
|
||||||
|
assert.equal($('#compose-textarea').val(), 'A$$\pi$$Bc');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -65,7 +65,13 @@ exports.replace_syntax = function (old_syntax, new_syntax, textarea) {
|
|||||||
textarea = $('#compose-textarea');
|
textarea = $('#compose-textarea');
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea.val(textarea.val().replace(old_syntax, new_syntax));
|
textarea.val(textarea.val().replace(old_syntax, function () {
|
||||||
|
// We need this anonymous function to avoid JavaScript's
|
||||||
|
// replace() function treating `$`s in new_syntax as special syntax. See
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Description
|
||||||
|
// for details.
|
||||||
|
return new_syntax;
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
|
|||||||
Reference in New Issue
Block a user