Skip to content

Small numbers get transformed into negative exponentials #80

Closed
@spassarop

Description

@spassarop

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

  1. 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:
    var snippet = "margin-left: 0.00001px";
    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.
  2. Parse the snippet with ParseDeclaration:
    var property = ParseDeclaration(snippet);
  3. 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 😞

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions