kisstkondoros / gutter-preview

Other
158 stars 37 forks source link

Update regex for data urls #127

Closed ianobermiller closed 2 years ago

ianobermiller commented 2 years ago

Make the regex for data urls simpler and work outside of CSS files. Since '") all have to be escaped in a data url, we can use that as an easy way to detect when it has terminated.

Test Plan

testfiles/test.css

.foo {
    background: url('data:image/webp;base64,UklGRigAAABXRUJQVlA4TBwAAAAvDoADEA8QEfMfQkEAMkw0zYjOboaI/of1gWN9');
}

image

testfiles/test.js

var _ = {
    url: 'data:image/webp;base64,UklGRigAAABXRUJQVlA4TBwAAAAvCoACEA8QEfMfQlHbNtCz8Av53DhE9D+Ey6MH',
};

image

kisstkondoros commented 2 years ago

Thanks for the PR! It works great for base64 encoded images, but it breaks for other encodings, e.g. data:image/svg+xml;utf8

I think the point is that we don't need the "url(" prefix and the trailing ")"

I'll prepare a fix for that.

kisstkondoros commented 2 years ago

To be fair, I just realized that it wasn't even supported properly :sweat_smile:

kisstkondoros commented 2 years ago

I've implemented this a little different, sorry for not merging this PR. The good news is that it should work in js files as well starting from v0.30.0.

ianobermiller commented 2 years ago

Works for me, thanks!