Skip to content

String value "0" gets converted to a float 0.0 while using the parser v8.3.0 #98

@DieWallSoCom

Description

@DieWallSoCom

Hi,

today I updated the jsonstreamimporter to version 8.3.0 and now the parser is converting the string number "0" to a float 0.0.

I found a bug in the file ParserHelper.php on the line 50.

...
public static function convertToNumber(string $text)
    {
        // thanks to #andig for the fix for big integers
        if (filter_var($text, FILTER_VALIDATE_INT) && (float) $text === (float) ((int) $text)) {
            // natural number PHP_INT_MIN < $num < PHP_INT_MAX
            return (int) $text;
        }

        // real number or natural number outside PHP_INT_MIN ... PHP_INT_MAX
        return (float) $text;
    }

The php function filter_var returns a 0 for filter_var($text, FILTER_VALIDATE_INT) if $text is "0", so that the if-condition evaluates to false.

It should be fixed to

...
   if (filter_var($text, FILTER_VALIDATE_INT) !== false && (float) $text === (float) ((int) $text)) {
...

so that "0" will be correctly parsed to the integer 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions