kangax / html-minifier

Javascript-based HTML compressor/minifier (with Node.js support)
http://kangax.github.io/html-minifier/
MIT License
4.92k stars 568 forks source link

PHP breaks when "?>" exist in string(s) or comment(s) #1125

Open millennIumAMbiguity opened 2 years ago

millennIumAMbiguity commented 2 years ago

When ?> exist in a comment or string, the PHP breaks.

The expected result should be the same as the input.

Before:

<?php

//this does not get formatted.

define("cars", [
  "Alfa Romeo",
  "BMW", //this "?>" will break the PHP. 
  "Toyota"
]);

//this get formatted. <h1 class="">

echo cars[0];

?>

After:

<?php

//this does not get formatted.

define("cars", [
  "Alfa Romeo",
  "BMW", //this "?>" will break the PHP. "Toyota" ]); //this get formatted.<h1>echo cars[0]; ?>