Fix rich_text highlighting bug with .cr file with a quotation mark
Summary
The syntax highlighting logic for Crystal (.cr) files incorrectly parses apostrophes/single quotes within comments, causing incorrect diff rendering in the merge request Changes tab. While the raw diff is correct, the syntax-highlighted version displays changes in the wrong locations.
Reported in https://gitlab.com/gitlab-com/request-for-help/-/issues/3780
Steps to reproduce
Any project on any version of GitLab;
- Create a .cr file
test {
hello: hi
// asdf
// my comment has an apostrophe 'this is all after`
// new comment 'string'
howareyou: good
}
- I remove the first
'on line 5. - Commit to new branch and create the resulting MR
- Check the changes tab of the MR.
Current behaviour
It would look something like this.
It seems that the rich_text highlighting logic has a bug in it as the raw text is fine.
text:
-\t// my comment has an apostrophe 'this is all after`
rich_text:
<span class=\"line\" data-lang=\"crystal\">\t<span class=\"sr\">//</span> <span class=\"n\">my</span> <span class=\"n\">comment</span> <span class=\"n\">has</span> <span class=\"n\">an</span> <span class=\"n\">apostrophe</span> <span class=\"s1\"><span class=\"idiff left right deletion\">'</span> '</span><span class=\"n\">string</span><span class=\"err\">'</span></span>
Edited by Sincheol (David) Kim
