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 + '&amp;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?

8 comments
Comment actions Permalink

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?

0
Comment actions Permalink

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

0
Comment actions Permalink

Typing &amp;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.

0
Comment actions Permalink

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...

Typing &amp;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.



0
Comment actions Permalink

I typed in the IDE:
&lt;span onclick="'&amp;lt;'"&gt;

and got attribute value in the parser:
'&lt;'

The string literal range is (0,3). Is it correct? I think it should be (0, 6) - the range in the original text.

0
Comment actions Permalink

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:

&lt;span onclick="x = '&amp;lt;' + name"&gt;

>

and got attribute value in the parser:
x = '&lt;' + name

>

Is it correct?



0
Comment actions Permalink

To reproduce the error please inject the javascript language into html attribute values and type in the attribute value
x &amp;lt;

The error is failed assertion in the

method, because two strings are different. The first string is injection host text (x &amp;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 "&amp;lt;" but replacement is "&amp;"

0

Please sign in to leave a comment.