Skip to content

Commit

Permalink
fixes #306. improves json testing
Browse files Browse the repository at this point in the history
  • Loading branch information
trullock committed Mar 16, 2022
1 parent 6c60533 commit 9a08d1d
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 10 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## vNext (unpublished)

## v1.18.9 (16 March 2022)
## v1.19.0 (16 March 2022)
- Fixed bug with boolean handling inside JSON

## v1.18.0 (16 March 2022)
- Added support for compressing `<script type="application/json">`

## v1.17.14 (8 March 2022)
Expand Down
6 changes: 4 additions & 2 deletions src/NUglify.Tests/Html/TestScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ public void LdJson()
""@type"": ""WebSite"",
""url"": ""https://domain.ext"",
""name"": ""Name Site"",
""isChecked"": true,
""alternateName"": null
}</script>";
output = @"<script>var js=""somevar""</script><script type=application/ld+json>{""@context"":""http://schema.org/"",""@type"":""WebSite"",""url"":""https://domain.ext"",""name"":""Name Site"",""alternateName"":null}</script>";
output = @"<script>var js=""somevar""</script><script type=application/ld+json>{""@context"":""http://schema.org/"",""@type"":""WebSite"",""url"":""https://domain.ext"",""name"":""Name Site"",""isChecked"":true,""alternateName"":null}</script>";
equal(minify(input), output);
}
[Test]
Expand All @@ -84,9 +85,10 @@ public void Json()
""@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"",""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);
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/NUglify.Tests/JavaScript/Bugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,11 @@ public void Bug305()
{
TestHelper.Instance.RunTest("-rename:all");
}

[Test]
public void Bug306()
{
TestHelper.Instance.RunTest("-js:json");
}
}
}
5 changes: 5 additions & 0 deletions src/NUglify.Tests/JavaScript/Common/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ public void RunTest(bool inputExpected, string extraArguments, params string[] e

args.AddLast(outputMapFile);
}
else if (option.Equals("-js:json", StringComparison.OrdinalIgnoreCase))
{
inputFile += ".json";
outputFile += ".json";
}
}
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/NUglify.Tests/NUglify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@
<Content Include="TestData\JS\Expected\Bugs\Bug199JS.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\Bugs\Bug199JSON.js">
<None Include="TestData\JS\Expected\Bugs\Bug199JSON.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</None>
<Content Include="TestData\JS\Expected\Bugs\Bug201.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -542,6 +542,9 @@
<Content Include="TestData\JS\Expected\Bugs\Bug285.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="TestData\JS\Expected\Bugs\Bug306.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="TestData\JS\Expected\Bugs\Bug305.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -1864,9 +1867,9 @@
<Content Include="TestData\JS\Expected\CommandLine\Expression.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\CommandLine\Expression_json.js">
<None Include="TestData\JS\Expected\CommandLine\Expression_json.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</None>
<Content Include="TestData\JS\Expected\CommandLine\Expression_prog.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -2881,9 +2884,9 @@
<Content Include="TestData\JS\Input\Bugs\Bug199JS.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Input\Bugs\Bug199JSON.js">
<None Include="TestData\JS\Input\Bugs\Bug199JSON.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</None>
<Content Include="TestData\JS\Input\Bugs\Bug201.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -2923,6 +2926,9 @@
<Content Include="TestData\JS\Input\Bugs\Bug305.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="TestData\JS\Input\Bugs\Bug306.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="TestData\JS\Input\Bugs\Bug57.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -2968,6 +2974,9 @@
<Content Include="TestData\JS\Input\Bugs\Bug264.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="TestData\JS\Input\CommandLine\Expression.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="TestData\JS\Input\Literals\TemplateLiteralsEscaped.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
1 change: 1 addition & 0 deletions src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug306.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"@context":"http://schema.org/","@type":"WebSite","url":"https://domain.ext","name":"Name Site","isChecked":true,"alternateName":null}
8 changes: 8 additions & 0 deletions src/NUglify.Tests/TestData/JS/Input/Bugs/Bug306.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": "http://schema.org/",
"@type": "WebSite",
"url": "https://domain.ext",
"name": "Name Site",
"isChecked": true,
"alternateName": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ 1, foo += bar ? function(window){ return window.location.href; }(window) : { loc: "none" } ]

// if we parse this as an expression, it will stop after the above expression and totally
// ignore the next expression
alert("great googley-moogley!");
1 change: 1 addition & 0 deletions src/NUglify/Html/HtmlMinifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ string MinifyJsOrCss(string text, HtmlScriptStyleElement type)
jsonSettings.Format = JavaScriptFormat.JSON;
jsonSettings.SourceMode = JavaScriptSourceMode.Expression;
jsonSettings.IgnoreConditionalCompilation = true;
jsonSettings.KillSwitch |= (long)TreeModifications.BooleanLiteralsToNotOperators;
result = Uglify.Js(text, "inner_js", jsonSettings);
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/NUglify/NUglify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/trullock/NUglify</RepositoryUrl>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.0</NetStandardImplicitPackageVersion>
<Version>1.18.0</Version>
<Version>1.19.0</Version>
<PackageLicenseExpression></PackageLicenseExpression>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down

0 comments on commit 9a08d1d

Please sign in to comment.