Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svg2tvgt: fix ParseNumberGeneric #29

Merged
merged 1 commit into from
Jul 10, 2024
Merged

Conversation

marler8997
Copy link
Contributor

This fixes a regression in recent commit b8e82bc.

That commit added the characters eE+- to the list of accepted characters within the middle of a float string. However, the +- characters are only valid immediately after the eE characters. This broke SVGS that don't use whitespace between floats with negative numbers. Consider the following snippet from a real SVG:

<path d="M0 9.913V.487c0-.435.514-.651.812-.34l6.551 ...

With the commit referenced above, the string 0-.435 gets interpreted as a single float value which fails to parse as a float. I've fixed this by splitting the function to parse floats into 3 parts:

  1. before the decimal point
    char first = AcceptChar("0123456789." + (allow_sign ? "+-" : ""));
    ScanWhile(char.IsDigit);
  1. after the decimal point
    if (first != '.' && ScanOne(".")) {
        ScanWhile(char.IsDigit);
    }
  1. the exponent
    if (ScanOne("eE")) {
        ScanOne("+-");
        ScanWhile(char.IsDigit);
    }

This fixes the parser so that it only includes the +- characters if they properly appear immediately after the eE characters.

This fixes a regression in recent commit b8e82bc.

That commit added the characters `eE+-` to the list of accepted characters
within the middle of a float string.  However, the `+-` characters are only
valid immediately after the `eE` characters.  This broke SVGS that don't
use whitespace between floats with negative numbers.  Consider the
following snippet from a real SVG:

```
<path d="M0 9.913V.487c0-.435.514-.651.812-.34l6.551 ...
```

With the commit referenced above, the string `0-.435` gets interpreted as a
single float value which fails to parse as a float.  I've fixed this
by splitting the function to parse floats into 3 parts:

1) before the decimal point

    char first = AcceptChar("0123456789." + (allow_sign ? "+-" : ""));
    ScanWhile(char.IsDigit);

2) after the decimal point

    if (first != '.' && ScanOne(".")) {
        ScanWhile(char.IsDigit);
    }

3) the exponent

    if (ScanOne("eE")) {
        ScanOne("+-");
        ScanWhile(char.IsDigit);
    }

This fixes the parser so that it only includes the `+-` characters if they
properly appear immediately after the `eE` characters.
@ikskuh ikskuh merged commit 17894e7 into TinyVG:main Jul 10, 2024
3 checks passed
@marler8997 marler8997 deleted the fixParseNumber branch July 10, 2024 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants