Skip to content

Commit 8140876

Browse files
chrisbobbegnprice
authored andcommitted
compose: Fix breakage of LaTeX delimiters in quote-and-reply
String.prototype.replace and String.prototype.replaceAll interpret certain sequences such as $$ within a string provided as the replacement argument. Because of this, LaTeX delimiters $$ were turning into $, and other sequences could duplicate part of the existing draft. Avoid this interpretation by providing a function. Fixes: zulip#5849
1 parent 98945cd commit 8140876

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/compose/ComposeBox.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
363363
setMessageInputValue(state =>
364364
state.value.replace(
365365
placeholder,
366-
`[${_('Failed to upload file: {fileName}', { fileName })}]()`,
366+
() => `[${_('Failed to upload file: {fileName}', { fileName })}]()`,
367367
),
368368
);
369369
continue;
@@ -372,7 +372,7 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
372372
const linkText = `[${fileName}](${response.uri})`;
373373
setMessageInputValue(state =>
374374
state.value.indexOf(placeholder) !== -1
375-
? state.value.replace(placeholder, linkText)
375+
? state.value.replace(placeholder, () => linkText)
376376
: `${state.value}\n${linkText}`,
377377
);
378378
}
@@ -448,7 +448,9 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
448448
zulipFeatureLevel,
449449
_,
450450
});
451-
setMessageInputValue(state => state.value.replace(quotingPlaceholder, quoteAndReplyText));
451+
setMessageInputValue(state =>
452+
state.value.replace(quotingPlaceholder, () => quoteAndReplyText),
453+
);
452454
messageInputRef.current?.focus();
453455
} finally {
454456
setActiveQuoteAndRepliesCount(v => v - 1);

src/users/userSelectors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ function interpretCustomProfileField(
250250
);
251251
const { subtype, url_pattern } = realmData;
252252
const pattern = url_pattern ?? realmDefaultExternalAccounts.get(subtype)?.url_pattern;
253-
const url = pattern == null ? undefined : new URL(pattern.replace('%(username)s', value));
253+
const url =
254+
pattern == null ? undefined : new URL(pattern.replace('%(username)s', () => value));
254255
if (!url) {
255256
logging.warn(
256257
`Missing url_pattern for custom profile field of type ExternalAccount, subtype '${subtype}'`,

0 commit comments

Comments
 (0)