futtta / autoptimize

Official Autoptimize repo on Github
https://autoptimize.com/pro/
GNU General Public License v2.0
283 stars 87 forks source link

Images inside `<script>` tags are broken #382

Closed Tymvie closed 2 years ago

Tymvie commented 2 years ago

Hello,

Some plugins insert images into script tags, for example:

<script>
var test = <?php echo wp_json_encode( '<img src="example.com">' ); ?>;
</script>

Autoptimize does not add backslashes before quotation marks. Therefore, the tag is broken:

<script>
var test = "<img decoding="async" src=\"example.jpg\">";
</script>

Thanks for the great plugin

futtta commented 2 years ago

Thanks for reporting, I'll look into it, but I will likely (have to) stop AO's image optimization from acting on img tags in script tags, if not the chance of things breaking is too high anyway ..

just so I'm clear; this is when using the "image optimization" option on the "images" tab, right?

Tymvie commented 2 years ago

@futtta yes

futtta commented 2 years ago

Additionally; can you test if this also happens when "lazyload images" is on (it should not)?

Tymvie commented 2 years ago

@futtta yes, this does not happen when "lazyload images" is enabled

futtta commented 2 years ago

@tymvie I just committed a fix, can you download the beta and test?

Tymvie commented 2 years ago

@futtta thank you, it works

hrispm commented 2 years ago

@futtta I can also confirm that this problem does not appear when the beta with the fix is installed.

futtta commented 2 years ago

just fyi; This was released as part of AO 3.0.4 earlier today :)

have a nice weekend and thank you for your assistance!

Tymvie commented 2 years ago

@futtta thank you, enjoy your weekend!