voku/HtmlMin

JSON in data-* attributes

nlemoine opened this issue · 1 comments

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

Thanks for the good bug report. 👍 The issue is fixed in version 3.1.7.