-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[HTML, XML] Don't interpret <?
and <%
inside CDATA section
#252
Comments
There is also diff --git a/lexers/LexHTML.cxx b/lexers/LexHTML.cxx
index 4a5e092d..8a97d90e 100644
--- a/lexers/LexHTML.cxx
+++ b/lexers/LexHTML.cxx
@@ -1390,6 +1390,10 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
else if (isMako && makoComment) {
}
+ // Ignore everything in XML CDATA until ]]>
+ else if (isXml && state == SCE_H_CDATA) {
+ }
+
// generic end of script processing
else if ((inScriptType == eNonHtmlScript) && (ch == '<') && (chNext == '/')) {
// Check if it's the end of the script tag (or any other HTML tag) Check for XML CDATA before processing the other conditions seems to solve both |
Above change only fix the bug for XML (
|
<?
inside CDATA section<?
and <%
inside CDATA section
A quick search for PHP examples shows PHP embedded in web pages, not stand-alone PHP (
PHP generated XML is also useful. There could be options to turn off pre-processors. |
I still think these options should default off for XML, as using PHP (or server-side technology) to preprocess XML is really rare (MIME configurations), otherwise most if not all use of |
It is not reasonable to break current applications. |
Please try again. Both options default to diff --git a/lexers/LexHTML.cxx b/lexers/LexHTML.cxx
index 4a5e092d..2089bfe7 100644
--- a/lexers/LexHTML.cxx
+++ b/lexers/LexHTML.cxx
@@ -724,6 +724,8 @@ struct OptionsHTML {
bool allowScripts = true;
bool isMako = false;
bool isDjango = false;
+ bool styleHTMLCDATA = true;
+ bool styleXMLCDATA = true;
bool fold = false;
bool foldHTML = false;
bool foldHTMLPreprocessor = true;
@@ -767,6 +769,12 @@ struct OptionSetHTML : public OptionSet<OptionsHTML> {
DefineProperty("lexer.xml.allow.scripts", &OptionsHTML::allowScripts,
"Set to 0 to disable scripts in XML.");
+ DefineProperty("lexer.html.cdata.tag", &OptionsHTML::styleHTMLCDATA,
+ "Set to 0 to disable styling within CDATA tags.");
+
+ DefineProperty("lexer.xml.cdata.tag", &OptionsHTML::styleXMLCDATA,
+ "Set to 0 to disable styling within CDATA tags.");
+
DefineProperty("lexer.html.mako", &OptionsHTML::isMako,
"Set to 1 to enable the mako template language.");
@@ -1221,6 +1229,7 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
const bool allowScripts = options.allowScripts;
const bool isMako = options.isMako;
const bool isDjango = options.isDjango;
+ const bool styleCDATA = (isXml ? options.styleXMLCDATA : options.styleHTMLCDATA);
const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", true);
const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", true);
const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", true);
@@ -1390,6 +1399,9 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
else if (isMako && makoComment) {
}
+ else if (state == SCE_H_CDATA && !styleCDATA) {
+ }
+
// generic end of script processing
else if ((inScriptType == eNonHtmlScript) && (ch == '<') && (chNext == '/')) {
// Check if it's the end of the script tag (or any other HTML tag) Here is a lua on double click function that can be added to SciTEStartup.lua to help see the difference when double clicking on the edit pane. function OnDoubleClick()
if editor:GetPropertyInt('lexer.html.cdata.tag', 1) == 1 then
editor.Property['lexer.html.cdata.tag'] = '0'
editor.Property['lexer.xml.cdata.tag'] = '0'
else
editor.Property['lexer.html.cdata.tag'] = '1'
editor.Property['lexer.xml.cdata.tag'] = '1'
end
end Note that the |
This is complex than I thought,
Above patch only fixed CDATA (original bug), I think we can add options to turn off pre-processors globally:
|
However, the motivating example in notepad-plus-plus/notepad-plus-plus#14576 does not appear to be intended for ASP or PHP processing and would be better treated as basic unprocessed XML. Perhaps the desire here is to avoid splitting file types into with/without preprocessing so the user doesn't have to deal with this choice. |
PHP does not understand HTML/XML elements:
ASP may (not test) understand HTML elements as it need to parse |
PHP control could have 3 states since
For ASP, the character just after |
Here is a patch that implements
|
|
…llow.php and lexer.html.allow.php.
Whitespace is not required and ASP examples with '<%` followed immediately by a call is common. |
Needs update Lines 104 to 105 in a6f1998
PHP script tag was removed in PHP 7, https://wiki.php.net/rfc/remove_alternative_php_tags
|
…llow.asp and lexer.html.allow.asp.
Created for https://sourceforge.net/p/scintilla/bugs/1078/.
Per https://html.spec.whatwg.org/multipage/syntax.html#cdata-sections and https://www.w3.org/TR/xml11/#sec-cdata-sect, CDATA section is a literal block and only the closing
]]>
is recognized. I think here are two fixes:<?
inside CDATA section forSCLEX_PHPSCRIPT
.<?
inside XML CDATA section (original bug), letSCLEX_HTML
as is.The text was updated successfully, but these errors were encountered: