fix: preserve $$ and other special chars in user input template substitution#6755
Open
octo-patch wants to merge 2 commits intoChatGPTNextWeb:mainfrom
Open
Conversation
added 2 commits
April 12, 2026 12:14
…Grok-4 models (fixes ChatGPTNextWeb#6593) xAI's Grok-3-mini and Grok-4 models do not accept the presence_penalty and frequency_penalty request parameters. Sending these params causes an API error. This change detects these model families and removes the unsupported parameters from the request payload.
…hatGPTNextWeb#6574) When user input contains JavaScript special replacement patterns like $$, $&, $', or $`, String.prototype.replace() interprets them as replacement directives: - $$ → $ (literal dollar sign) - $& → the matched substring - $' → string after match - $` → string before match This caused e.g. $$e=mc^2$$ (display math) to be stored as $e=mc^2$ (inline math) after going through fillTemplateWith(). Fix: use a function callback in .replace() to treat the replacement value as a literal string, bypassing all special replacement patterns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6574
Problem
When a user sends a message containing
$$...$$(LaTeX display math), the double dollar signs get silently converted to single dollar signs ($...$, inline math) in the stored message. The preview bubble (shown while typing) renders correctly because it uses the raw input string directly, but after submission the content passes throughfillTemplateWith(), which usesString.prototype.replace()with the user input as the literal replacement string.JavaScript's
String.prototype.replace()treats several patterns in the replacement string as special directives:$$$$&$'$`So
"{{input}}".replace(/{{input}}/g, "$$e=mc^2$$")returns"$e=mc^2$"— stripping one pair of dollar signs.The same issue affects any user input containing
$&,$', or$`.Solution
Use a function callback in
.replace()instead of a string literal. When the replacement is a function, JavaScript passes no special treatment to its return value:Testing
All other special patterns (
$&,$',$`) are also fixed by this single change.