Skip to content

Commit

Permalink
compose: Fix breakage of LaTeX delimiters in quote-and-reply
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chrisbobbe committed Apr 6, 2024
1 parent c383d25 commit 751a9ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/compose/ComposeBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
setMessageInputValue(state =>
state.value.replace(
placeholder,
`[${_('Failed to upload file: {fileName}', { fileName })}]()`,
() => `[${_('Failed to upload file: {fileName}', { fileName })}]()`,
),
);
continue;
Expand All @@ -372,7 +372,7 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
const linkText = `[${fileName}](${response.uri})`;
setMessageInputValue(state =>
state.value.indexOf(placeholder) !== -1
? state.value.replace(placeholder, linkText)
? state.value.replace(placeholder, () => linkText)
: `${state.value}\n${linkText}`,
);
}
Expand Down Expand Up @@ -448,7 +448,9 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
zulipFeatureLevel,
_,
});
setMessageInputValue(state => state.value.replace(quotingPlaceholder, quoteAndReplyText));
setMessageInputValue(state =>
state.value.replace(quotingPlaceholder, () => quoteAndReplyText),
);
messageInputRef.current?.focus();
} finally {
setActiveQuoteAndRepliesCount(v => v - 1);
Expand Down
3 changes: 2 additions & 1 deletion src/users/userSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ function interpretCustomProfileField(
);
const { subtype, url_pattern } = realmData;
const pattern = url_pattern ?? realmDefaultExternalAccounts.get(subtype)?.url_pattern;
const url = pattern == null ? undefined : new URL(pattern.replace('%(username)s', value));
const url =
pattern == null ? undefined : new URL(pattern.replace('%(username)s', () => value));
if (!url) {
logging.warn(
`Missing url_pattern for custom profile field of type ExternalAccount, subtype '${subtype}'`,
Expand Down

0 comments on commit 751a9ec

Please sign in to comment.