-
Notifications
You must be signed in to change notification settings - Fork 120
PHP syntax not recognized inside HTML quotes #409
Comments
I'm afraid this is As I always say in these issues: try to avoid injections all together, there are better ways to pass data between languages. |
VS Code handles it perfectly though (see screenshot below). Plus, PHP and HTML are meant to co-exist by design, and I think that syntax is a lot better than something like But however you'd prefer to write this, Atom isn't behaving as expected, and VS Code is, so I'm not sure why fixing this would be off-limits, while the people working on VS Code have clearly figured it out. |
I wouldn't call it a VSC doesn't parse CSS inside <style>
div {
background-image: url(a<?= $image_url; ?>);
}
</style> which based on my testing exhibits the same behavior where it isn't working mid-text. |
@wasinwill You were saying? VSCode and atom are using different syntax for css and html. I'm not sure what is go-to nowadays for php/html templating, but I'm sure there are better ways which have full IDE support. Even going with attribute and propagating this with JS might be better. @Ingramz We have so many problems like that with SQL and HTML that I'm rather confident this will be at least time consuming to mitigate. And I've checked what tokens are involved in this. |
@KapitanOczywisty I'm confused. Your screenshot shows that it doesn't work inside <style> tags (same for me) but does work in HTML on your end. So if we put aside <style> tags, you're saying you're not seeing the issue on your machine? PS: I won't add JS to a file in order to fetch the URL of an image and set it as a CSS rule to a single div on a page just because my text editor won't highlight |
@wasinwill In style attr you don't have syntax highlighting in vscode, that is why it's working. I'm saying in general, there is no point for one instance, but If you have more data passed from php to html like that It's good to think about template system. I've been writing code like that nearly 10 years and now when I need to do something in these projects I'm contemplating about my life choices. It's getting out of hands very quickly. Now I'm mainly working with React, so I'm not sure what would be good in your case. To fix this we need to add special injection for that exact token. I'm not sure what would be long-term consequences performance-wise. Edit: However, I'll think about that since you cannot use variable in .count:after {
content: 'The count is ' attr(data-count) '.';
} |
@KapitanOczywisty There are cases like setting Now, maybe you're right and fixing this will have consequences on performance and it's just not worth it. I guess it's a decision that you guys have to make. |
@wasinwill When testing I've found that it's working with single-quotes, so fix may be not needed after all. <div style="background-image:url('/img/<?=$image_url?>.jpg')"></div> |
I had some time to look into it and mostly it's about how CSS grammar consumes the contents of the It is sufficient to just remove the |
@Ingramz but then every single character is separate token, counting to 100 may be fast. |
@KapitanOczywisty definitely a valid concern, but also fixable by re-arranging the grammar a bit. It looks like the pattern can be omitted entirely and replaced with a |
If an HTML code similar to
style="background-image:url(<?= $image_url ?>)"
is added to a .php file, Atom fails to recognize PHP tags if any character is entered afterurl(
. See picture below:After inspecting the elements with Developer Tools, it looks like it isn't theme-related. The example below shows when it works, with a code like
url(<?= $image_url ?>)
. The tag is recognized and encapsulted inside asyntax--php
element.However, when a character is added after the bracket, such as
url(/img/<?= $image_url ?>.jpg)
, the tag is no longer recognized and sits inside asyntax-css
element.Version 1.53.0 x64
Electron 6.1.12
Chrome 76.0.3809.146
Node v12.4.0
Theme One Dark
The text was updated successfully, but these errors were encountered: