Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
eslint: Fix unicorn/no-unsafe-string-replacement.
Anders Kaseorgdbcee1516aad
diff --git a/web/src/markdown.ts b/web/src/markdown.tsindex bf314cd7914..e8bac4daa62 100644--- a/web/src/markdown.ts+++ b/web/src/markdown.ts@@ -104,43 +104,34 @@ export function translate_emoticons_to_names({}): string {// Translates emoticons in a string to their colon syntax.let translated = src;- let replacement_text: string;const terminal_symbols = ",.;?!()[] \"'\n\t"; // From composebox_typeaheadconst symbols_except_space = terminal_symbols.replace(" ", "");- const emoticon_replacer = function (- match: string,- _capture_group: string,- offset: number,- str: string,- ): string {- const prev_char = str[offset - 1];- const next_char = str[offset + match.length];-- const non_space_at_start =- prev_char !== undefined && symbols_except_space.includes(prev_char);- const non_space_at_end =- next_char !== undefined && symbols_except_space.includes(next_char);- const valid_start = prev_char === undefined || terminal_symbols.includes(prev_char);- const valid_end = next_char === undefined || terminal_symbols.includes(next_char);-- if (non_space_at_start && non_space_at_end) {- // Hello!:)?- return match;- }- if (valid_start && valid_end) {- return replacement_text;- }- return match;- };-for (const translation of get_emoticon_translations()) {- // We can't pass replacement_text directly into- // emoticon_replacer, because emoticon_replacer is- // a callback for `replace()`. Instead we just mutate- // the `replacement_text` that the function closes on.- replacement_text = translation.replacement_text;- translated = translated.replace(translation.regex, emoticon_replacer);+ const replacement_text = translation.replacement_text;+ translated = translated.replace(+ translation.regex,+ (match, _capture_group, offset: number, str: string) => {+ const prev_char = str[offset - 1];+ const next_char = str[offset + match.length];++ const non_space_at_start =+ prev_char !== undefined && symbols_except_space.includes(prev_char);+ const non_space_at_end =+ next_char !== undefined && symbols_except_space.includes(next_char);+ const valid_start = prev_char === undefined || terminal_symbols.includes(prev_char);+ const valid_end = next_char === undefined || terminal_symbols.includes(next_char);++ if (non_space_at_start && non_space_at_end) {+ // Hello!:)?+ return match;+ }+ if (valid_start && valid_end) {+ return replacement_text;+ }+ return match;+ },+ );}return translated;diff --git a/web/tests/list_widget.test.cjs b/web/tests/list_widget.test.cjsindex 85ac6029240..afb0cdc81be 100644--- a/web/tests/list_widget.test.cjs+++ b/web/tests/list_widget.test.cjs@@ -26,8 +26,8 @@ mock_jquery((arg) => {addClass() {return this;},- replace(regex, string) {- arg = arg.replace(regex, string);+ _replace(regex, string) {+ arg = arg.replace(regex, () => string);},html: () => arg,};@@ -860,7 +860,7 @@ run_test("render item", () => {replaceWith($element) {assert.equal(new_html, $element.html());called = true;- $container.$appended_data.replace(regex, new_html);+ $container.$appended_data._replace(regex, new_html);},length: 1,};