Language injected to the HTML attribute: don't encode attribute values
I have injected the language into HTML attribute values.
The problem: if the attribute value looks like "1 + '&lt;' + 2" then I receive the "1 + '<' + 2" in the parser (original string of the PsiBuilder).
How to prevent HTML entity replacing in the injected language fragments?
Please sign in to leave a comment.
I think that the Idea transforms HTML attribute value using XmlAttributeLiteralEscaper instance and passes transformed value to the parser. Does Idea transform HTML attribute values for injected javascript fragments?
This is by design and AFAIK cannot be prevented with the current API. Why do you want to get the encoded text in the parser? Unless your injected language know about HTML entity encoding, it will not be able to parse the encoded text - which applies to 100% of all currently known language implementations. Please see the discussion in IDEADEV-5500.
There's an inconsistency though: On AST/PSI-level, you will see the entities again, but I consider this as a bug rather than a feature (IDEADEV-11213).
Sascha
Typing &lt; in the attribute value leads to exception in the InjectedLanguageUtil.a() method (seems this code compares text in the document and text of resulting ast nodes) and IDE starts to add symbols. Did you have similar problem?
I think that HTML entity replacement is reason of the problem.
Could you please post an exception to the jira?
--
regards,
--
Alexey Kudravtsev
Software Developer
JetBrains, Inc, http://www.jetbrains.com
"Develop with pleasure!"
"Alex Orishchenko" <no_mail@jetbrains.com> wrote in message
news:17457891.1169050503259.JavaMail.itn@is.intellij.net...
>
http://www.jetbrains.net/jira/browse/IDEA-11057
I typed in the IDE:
<span onclick="'&lt;'">
and got attribute value in the parser:
'<'
The string literal range is (0,3). Is it correct? I think it should be (0, 6) - the range in the original text.
Yes, it is correct.
contents of xml attribute is decoded before feeding to the parser.
--
regards,
--
Alexey Kudravtsev
Software Developer
JetBrains, Inc, http://www.jetbrains.com
"Develop with pleasure!"
"Alex Orishchenko" <no_mail@jetbrains.com> wrote in message
news:33179989.1169116915965.JavaMail.itn@is.intellij.net...
>I typed in the IDE:
>
>
To reproduce the error please inject the javascript language into html attribute values and type in the attribute value
x &lt;
The error is failed assertion in the
method, because two strings are different. The first string is injection host text (x &lt;), the second is adjusted ast node text. The adjustment is performed by InjectedLanguageUtil.a(ASTNode , LiteralTextEscaper , String , int , int ). But the expected result is replace "<" by "&lt;" but replacement is "&"