voku / HtmlMin

:clamp: HtmlMin: HTML Compressor and Minifier via PHP
MIT License
161 stars 22 forks source link

JSON in data-* attributes #35

Closed nlemoine closed 5 years ago

nlemoine commented 5 years ago

What is this feature about (expected vs actual behaviour)?

Minification is breaking JSON placed in data-* attributes. Actually, it doesn't "break" the JSON part, it replaces single quotes with double quotes.

<div data-json='{"key":"value"}'></div>

Becomes:

<div data-json="{"key":"value"}"></div>

Unfortunalety, you can't use single quotes in JSON. But you can use single quotes in HTML.

How can I reproduce it?

<?php

require_once 'vendor/autoload.php';

use voku\helper\HtmlMin;

$htmlMin = new HtmlMin();

ob_start();
?>
<html>
  <body>
    <div data-json='{"key":"value"}'></div>
  </body>
</html>
<?php
$html = ob_get_clean();

echo $htmlMin->minify($html); 

Does it take minutes, hours or days to fix?

I have no idea, I didn't dig into code.

voku commented 5 years ago

Thanks for the good bug report. :+1: The issue is fixed in version 3.1.7.