trullock / NUglify

NUglify is a HTML, JavaScript and CSS minification Library for .NET (fork of AjaxMin + new features)
Other
398 stars 79 forks source link

JSON boolean values are stripped #306

Closed AndyMcKenna closed 2 years ago

AndyMcKenna commented 2 years ago

Describe the bug In v1.18.0, when minimizing JSON with a boolean property, the true/false value is stripped in the output

To Reproduce Modify the TestScripts.Json test method

        public void Json()
        {

            input = @"
<script type=text/javascript>
var js=""somevar"";
</script>
<script type=application/json>{
    ""@context"": ""http://schema.org/"",
    ""@type"": ""WebSite"",
    ""url"": ""https://domain.ext"",
    ""name"": ""Name Site"",
    ""isChecked"": true,
    ""alternateName"": null
}</script>";
            output = @"<script>var js=""somevar""</script><script type=application/json>{""@context"":""http://schema.org/"",""@type"":""WebSite"",""url"":""https://domain.ext"",""name"":""Name Site"",""isChecked"":true,""alternateName"":null}</script>";
            equal(minify(input), output);
        }

Minified output or stack trace From the test:

<script type=text/javascript>
var js="somevar";
</script>
<script type=application/json>{
    "@context": "http://schema.org/",
    "@type": "WebSite",
    "url": "https://domain.ext",
    "name": "Name Site",
    "isChecked": true,
    "alternateName": null
}</script>
inner_js: warning : Invalid JSON JavaScript nodes encountered during output
======
OUTPUT
------
<script>var js="somevar"</script><script type=application/json>{"@context":"http://schema.org/","@type":"WebSite","url":"https://domain.ext","name":"Name Site","isChecked":,"alternateName":null}</script>
========
EXPECTED
--------
<script>var js="somevar"</script><script type=application/json>{"@context":"http://schema.org/","@type":"WebSite","url":"https://domain.ext","name":"Name Site","isChecked":true,"alternateName":null}</script>

I tracked it down to true getting changed to !0 which looks like it's controlled by TreeExpressions.BooleanLiteralsToNotOperators but I can't find what setting sets that flag on KillSwitch

trullock commented 2 years ago

What are we saying is the issue here, that it outputs empty (surely this) or that it outputs 0! rather than true?

AndyMcKenna commented 2 years ago

That it outputs empty, yeah. It's outputting empty because the true gets converted to !0 along the way and that's what is causing the invalid JSON node warning

trullock commented 2 years ago

yep, on it.