Repository navigation
fix(react):fix(react): prevent intra-word and whitespace-flanked markdown emphasis in composer - #1418
Open
swarnendusahu10-dotcom wants to merge 1 commit into
Conversation
…hasis in composer Prevents intra-word underscores and whitespace-flanked asterisks from being parsed as emphasis in contentEditableComposer.js. CommonMark and GFM specify that underscore delimiters cannot open or close emphasis when adjacent to word characters, and emphasis markers cannot be flanked by whitespace. Previously, identifiers (e.g. my_file_name.js, foo_bar_baz) and arithmetic (e.g. 2 * 3 * 4) were corrupted into <em> and <strong> tags when rendered in the composer. Fixes RocketChat#1372
This branch has not been deployed
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.
Description
Fixes #1372
In the AI contentEditable composer (
contentEditableComposer.js), markdown emphasis regex patterns did not adhere to CommonMark/GFM flanking specifications. As a result:my_file_name.js,user_id_token) had their inner words corrupted into italic<em>tags (e.g.,my<em>file</em>name.js).2 * 3 * 4) were erroneously parsed as bold/italic.Cause & Solution
_): Per CommonMark specs, underscores cannot open or close emphasis if preceded or followed by word characters (non-word boundary requirement). Updated regex requires word boundaries/non-word characters so snake_case identifiers remain literal.*): Required whitespace non-flanking checks so asterisks used in math or bullet contexts are not parsed as emphasis formatting.*bold*,_italic_) outside words continue to work seamlessly.Type of Change
How Has This Been Tested?
my_file_name.js,foo_bar_baz,variable_name-> preserved untouched.2 * 3 * 4,10 / 2 * 5-> preserved untouched.*italic*,**bold**,_italic_,__bold__-> formatted correctly into<em>and<strong>.**_bold and italic_**-> formatted correctly.