Detection of a "Begin String" phrase or "End String" phrase for syntax highlighting does not work when there is a backslash in front of the "Begin String" phrase or "End String" phrase #1686
Start with a syntax highlighting rule similar to the following screenshot. For this demonstration, I will create the syntax highlighting rule in the String category, but this bug appears to occur regardless of the syntax highlighting category the syntax highlighting rule is created in. The syntax highlighting rule should have the Regular Expression option disabled, have a phrase set for the Begin String option, and have a phrase set for the End String option. I'll refer to the phrase set for the Begin String option as the Beginning Phrase and the phrase set for the End String option as the Ending Phrase.
The Beginning Phrase and Ending Phrase can either be a single character or a set of multiple characters. For this demonstration, I will set the Beginning Phrase to ab and Ending Phrase to xyz, but this bug appears to occur with any characters, including symbols and numbers. While I will set the Beginning Phrase and Ending Phrase to be different in this demonstration, this bug will still occur if the Beginning Phrase and Ending Phrase are the same.
For this demonstration, I will disable the Ignore Case option, but this bug still occurs when the Ignore Case option is enabled.
For this demonstration, I have set the Syntax Kind to Code, but this bug seems to still occur when the Syntax Kind is set to General.
If I type the Starting Phrase and Ending Phrase and add a \ before the Ending Phrase, the syntax highlighting seems not to detect the Ending Phrase, so there is no syntax highlighting. (In all of the screenshots, I have added some text after the string and in the next line after the string to show whether the syntax highlighting continues beyond the string, but this bug still occurs without these texts.)
If the \ is instead added before the Starting Phrase, a similar situation occurs in which there will be no syntax highlighting.
Normally, if I type the Ending Phrase twice, the syntax highlighting will end after the first instance of the Ending Phrase.
However, if there is a \ before the first instance of the Ending Phrase, that first instance of the Ending Phrase seems to be ignored, and the syntax highlighting will instead end after the second instance of the Ending Pharse.
This behavior also occurs if there is text between the Starting Phrase and the first instance of the Ending Phrase.
This behavior also occurs if there is text between the first and second instance of the Ending Phrase.
The syntax highlighting will also continue across lines.
Normally, if there are multiple instances of the Starting Phrase before the Ending Phrase, the syntax highlighting starts from the first instance of the Starting Phrase.
However, if a \ is added before the first instance of the Starting Phrase, that first instance of the Starting Pharse seems to be ignored, and the syntax highlighting will instead start from the second instance of the Starting Phrase.
To Reproduce
Go to settings and create a new syntax. I'll refer to this new syntax as Demonstration Syntax.
In any highlighting category, create a new highlighting rule. I will use the string highlighting rule, but this bug seems to occur with all of the highlighting categories.
Ensure the Regular Expression option is disabled for this new highlighting rule.
I disabled the Ignore Case option, but this bug still seems to occur when the Ignore Case option is enabled.
Add a character or multiple characters in the Begin String option. I added the ab character, but this bug seems to occur with any singular character or set of multiple characters added to the Begin String option.
Add a character or multiple characters in the End String option. I added the xyz character, but this bug seems to occur with any singular character or set of multiple characters added to the End String option.
Create a new file.
Set the syntax to Demonstration Syntax.
Type in the phrase you set to the Begin String option.
Type in the phrase you set to the End String option.
Type in a \ before the phrase you set to the 'End String' option. (If you used the same settings for the Begin String and End String option as me, you should have typed in ab\xyz).
You should be able to observe the bug now: the text you just typed in will not be highlighted.
At the end of the text you already typed in, type in the phrase you set to the End String option. (If you used the same settings for the Begin String and End String option as me, you should have typed in ab\xyzxyz).
Observe how the highlighting does not end at the first instance of the phrase you set to the End String option.
Delete all of the text you have typed in.
Type in the phrase you set to the Begin String option.
Type in the phrase you set to the End String option.
Type in a \ before the phrase you set to the 'Begin String' option. (If you used the same settings for the Begin String and End String option as me, you should have typed in \abxyz).
Observe how the text you just typed in will not be highlighted.
Right after the Begin String phrase you have typed in, type in the phrase you set to the Begin String option. (If you used the same settings for the Begin String and End String option as me, you should have typed in \ababxyz).
Observe how the highlighting does not start at the first instance of the phrase you set to the Begin String option.
Expected behavior
The expected behavior is described in the description.
CotEditor version
4.8.7 (657)
macOS version
14.5
Additional context
I initially discovered this bug when writing strings that ended in a \.
Description
Start with a syntax highlighting rule similar to the following screenshot. For this demonstration, I will create the syntax highlighting rule in the
String
category, but this bug appears to occur regardless of the syntax highlighting category the syntax highlighting rule is created in. The syntax highlighting rule should have theRegular Expression
option disabled, have a phrase set for theBegin String
option, and have a phrase set for theEnd String
option. I'll refer to the phrase set for theBegin String
option as theBeginning Phrase
and the phrase set for theEnd String
option as theEnding Phrase
.The
Beginning Phrase
andEnding Phrase
can either be a single character or a set of multiple characters. For this demonstration, I will set theBeginning Phrase
toab
andEnding Phrase
toxyz
, but this bug appears to occur with any characters, including symbols and numbers. While I will set theBeginning Phrase
andEnding Phrase
to be different in this demonstration, this bug will still occur if theBeginning Phrase
andEnding Phrase
are the same.For this demonstration, I will disable the
Ignore Case
option, but this bug still occurs when theIgnore Case
option is enabled.For this demonstration, I have set the
Syntax Kind
toCode
, but this bug seems to still occur when theSyntax Kind
is set toGeneral
.If I type the
Starting Phrase
andEnding Phrase
and add a\
before theEnding Phrase
, the syntax highlighting seems not to detect theEnding Phrase
, so there is no syntax highlighting. (In all of the screenshots, I have added some text after the string and in the next line after the string to show whether the syntax highlighting continues beyond the string, but this bug still occurs without these texts.)If the
\
is instead added before theStarting Phrase
, a similar situation occurs in which there will be no syntax highlighting.Normally, if I type the
Ending Phrase
twice, the syntax highlighting will end after the first instance of theEnding Phrase
.However, if there is a
\
before the first instance of theEnding Phrase
, that first instance of theEnding Phrase
seems to be ignored, and the syntax highlighting will instead end after the second instance of theEnding Pharse
.This behavior also occurs if there is text between the
Starting Phrase
and the first instance of theEnding Phrase
.This behavior also occurs if there is text between the first and second instance of the
Ending Phrase
.The syntax highlighting will also continue across lines.
Normally, if there are multiple instances of the
Starting Phrase
before theEnding Phrase
, the syntax highlighting starts from the first instance of theStarting Phrase
.However, if a
\
is added before the first instance of theStarting Phrase
, that first instance of theStarting Pharse
seems to be ignored, and the syntax highlighting will instead start from the second instance of theStarting Phrase
.To Reproduce
Demonstration Syntax
.Regular Expression
option is disabled for this new highlighting rule.Ignore Case
option, but this bug still seems to occur when theIgnore Case
option is enabled.Begin String
option. I added theab
character, but this bug seems to occur with any singular character or set of multiple characters added to theBegin String
option.End String
option. I added thexyz
character, but this bug seems to occur with any singular character or set of multiple characters added to theEnd String
option.Demonstration Syntax
.Begin String
option.End String
option.\
before the phrase you set to the 'End String' option. (If you used the same settings for theBegin String
andEnd String
option as me, you should have typed inab\xyz
).End String
option. (If you used the same settings for theBegin String
andEnd String
option as me, you should have typed inab\xyzxyz
).End String
option.Begin String
option.End String
option.\
before the phrase you set to the 'Begin String' option. (If you used the same settings for theBegin String
andEnd String
option as me, you should have typed in\abxyz
).Begin String
phrase you have typed in, type in the phrase you set to theBegin String
option. (If you used the same settings for theBegin String
andEnd String
option as me, you should have typed in\ababxyz
).Begin String
option.Expected behavior
The expected behavior is described in the description.
CotEditor version
4.8.7 (657)
macOS version
14.5
Additional context
I initially discovered this bug when writing strings that ended in a
\
.