Skip to content

parse_ini_file parse_ini_string bug when when INI_SCANNER_TYPED #11010

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

Closed
GajowyJ opened this issue Apr 4, 2023 · 6 comments
Closed

parse_ini_file parse_ini_string bug when when INI_SCANNER_TYPED #11010

GajowyJ opened this issue Apr 4, 2023 · 6 comments

Comments

@GajowyJ
Copy link

GajowyJ commented Apr 4, 2023

Description

The following code:

<?php
$txt = "variable = -00 20 30";
$ret=parse_ini_string($txt,FALSE,INI_SCANNER_TYPED);
var_dump($ret['variable']);

Resulted in this output:

string(7) "0 20 30"

But I expected this output instead:

string(9) "-00 20 30"

or

int(0)

PHP Version

PHP 8.1.17

Operating System

Windows 10

@iluuu1994
Copy link
Member

The INI scanner converts each token (word) independently. If it is convertible (analogous to is_numeric in PHP) it will be, no matter where after = it appears. https://3v4l.org/0BjuD We might want to try converting the values only in the parser when they appear as standalone values (i.e. when they aren't part of some other expression). I'll give that a shot.

iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Apr 4, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Apr 4, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Apr 4, 2023
@GajowyJ
Copy link
Author

GajowyJ commented Apr 21, 2023

@iluuu1994
Nothing has changed in PHP v 8.1.18. The issue still exists. Shouldn't the ticket be reopened?

@damianwadley
Copy link
Member

@GajowyJ The fix has only been added to master, which means as things are now it will only be present in the next series of PHP (probably 8.3).

@iluuu1994 Is that intentional?

@iluuu1994
Copy link
Member

This was indeed intentional because the changes were non-trivial and affect all of ini parsing. Sorry @GajowyJ, my communication was clearly inadequate here.

@iluuu1994
Copy link
Member

@GajowyJ The way you can avoid this at the moment is to wrap the value in double quotes (""). https://3v4l.org/QSBA3

@GajowyJ
Copy link
Author

GajowyJ commented Apr 21, 2023

@iluuu1994 @damianwadley
Thank you for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants