Description
Bug Report
Prerequisites
- Can you reproduce the problem in a MWE?
- Are you running the latest version of AngleSharp?
- Did you check the FAQs to see if that helps you?
- Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g.,
AngleSharp.Css
for CSS support) - Did you perform a search in the issues?
For more information, see the CONTRIBUTING
guide.
Description
Small numbers like 0.00001 get transformed into exponentials like 1E-05 due to internal value parsing. This does not happen with large numbers like 100000000.
Steps to Reproduce
- Create a declaration containing a margin-left (could be any margin side) with a value of 0.00001px. I just used the first test on src\AngleSharp.Css.Tests\Declarations\CssMarginProperty.cs and changed it to my test values. It could be:
In my project which consumes AngleSharp.Css I used CssParser.ParseStyleSheet() and inspecting the result, the property was in exponential format. This would skip the next two steps.
var snippet = "margin-left: 0.00001px";
- Parse the snippet with
ParseDeclaration
:var property = ParseDeclaration(snippet);
- Check that property value is now in exponential format.
Expected behavior: Output is margin-left: 0.00001px
.
Actual behavior: Output is margin-left: 1E-05px
. I wouldn't mind if I use the value to apply on CSS as it's semantically the same. The problem is that the use I give AngleSharp.Css is to clean bad styles on a general HTML, looking for malicious input. Users of my library expect to receive the same HTML they used as input to clean.
Environment details: Windows 10, .NET Core 2.1, AngleSharp.Css 0.16.1, AngleSharp 0.16.0.
Possible Solution
This one is too deep for me; I don't know the internals of the project that much to propose a solution 😞