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

Fix values similar to booleans being incorrectly parsed to booleans #168

Merged
merged 4 commits into from
Jan 31, 2022
Merged

Conversation

MrGreenTea
Copy link
Contributor

This included values that strat with t or f like test and friend as well as values that have true or false as prefix like truely and falsely.

All of them are now incorrectly rejected by tomlkit.value.

Closes #165

tomlkit/parser.py Outdated Show resolved Hide resolved
@frostming
Copy link
Contributor

frostming commented Jan 29, 2022

Sorry, I revisited the original issue and fix, and came up with a different fix approach.

The real problem here are 1) the error isn't thrown correctly and 2) the value() API doesn't check the EOF of the given string.

The parsing of boolean values is correct and doesn't need a fix. So can you kindly revert the change in parsing but ensure the EOF is reached after value parsing. This approach doesn't only fix the boolean parsing, but it also fixes other incomplete parsings like "som string"1.23.

Thanks for your patience.

@MrGreenTea
Copy link
Contributor Author

I'm not sure I follow exactly. Can you provide me with some tests that reproduce the behaviour you expect? Or some examples?

@frostming
Copy link
Contributor

tomlkit.value('"foo"1.2')
# should reject

the current behavior parses as 'foo' but it doesn't reach the end. 1.2 is remaining unparsed, we should check against this case. Then the original issue will also be fixed.

@MrGreenTea
Copy link
Contributor Author

If I understand you correctly, we should check if EOF was reached when parsing a value?
Would a simple check like this suffice?

if not self.end():
    raise ParseError

@frostming
Copy link
Contributor

lgtm, but it only applies to value api so it should be parser.end()

also a meaningful error message would be good

@frostming
Copy link
Contributor

LGTM! Thanks

@frostming frostming merged commit 193b859 into python-poetry:master Jan 31, 2022
@MrGreenTea
Copy link
Contributor Author

@frostming thanks for the help! Is there a chance to get a new release with this bugfix soon?

capuanob pushed a commit to capuanob/tomlkit that referenced this pull request Mar 1, 2023
Fix values similar to booleans being incorrectly parsed to booleans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: tomlkit.value("test") returns True
2 participants