Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline styles with inner quotes have parsing issues #2715

Closed
trongthanh opened this issue May 8, 2019 · 4 comments · Fixed by #2754
Closed

Inline styles with inner quotes have parsing issues #2715

trongthanh opened this issue May 8, 2019 · 4 comments · Fixed by #2754

Comments

@trongthanh
Copy link

trongthanh commented May 8, 2019

Svelte 3.2.1

Here's the REPL link to demonstrate.

Basically, I need to use inline styles for background-image since the image URL is dynamic. And, because of habit, I add the quotes surround the image URL in url() function like so:

<div style="background-image: url('{bgImage}')">This work!</div>

But as soon as I added the trailing semi (so that I can append another style rule), the inline style broke and nothing render for the style attributes.

<div style="background-image: url('{bgImage}');">This does NOT work!</div>

My current workaround is to omit the inner quotes (it is completely optional in CSS url() but may be content and other properties might need them).

@EmilTholin
Copy link
Member

EmilTholin commented May 8, 2019

Hi @trongthanh! Thank you so much for this great research and all the examples!

The second example fails because the ; becomes a part of the argument passed to set_style in the generated code, which is not allowed.

set_style(div, "background-image", "url('" + bgImage + "');");

The third example fails because the rest of the style string gets passed to set_style for the background-image.

set_style(div, "background-image", "url('" + bgImage + "'); color:" + color);

@bwbroersma
Copy link
Contributor

Indeed something is going wrong in StyleAttribute.ts.
; should work in my opinion, but is not properly split at the moment.

@bwbroersma
Copy link
Contributor

Also !important is going wrong.

@EmilTholin
Copy link
Member

EmilTholin commented May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants