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

Incorrectly parsing fractions of a second when not enough digits are given #314

Open
programmerjake opened this issue Sep 8, 2020 · 2 comments
Labels
component: decoder Related to parsing in `toml.load` syntax: date/time Related to dates, times or datetimes type: bug A confirmed bug or unintended behavior

Comments

@programmerjake
Copy link

I'm using toml 0.10.1 downloaded from PyPI on CPython 3.8.0 on Linux.

My code:

import toml
for i in range(1, 8):
    v = "12:34:56." + "1234567"[:i]
    print(v, toml.loads("a=" + v)['a'])

Output:

12:34:56.1 12:34:56
12:34:56.12 12:34:56
12:34:56.123 12:34:56.000123
12:34:56.1234 12:34:56.001234
12:34:56.12345 12:34:56.012345
12:34:56.123456 12:34:56.123456
12:34:56.1234567 12:34:56.123456

Expected output:

12:34:56.1 12:34:56.100000
12:34:56.12 12:34:56.120000
12:34:56.123 12:34:56.123000
12:34:56.1234 12:34:56.123400
12:34:56.12345 12:34:56.123450
12:34:56.123456 12:34:56.123456
12:34:56.1234567 12:34:56.123456
@markman123
Copy link

Submitted a fix that passes your example. It was throwing away 1-2 characters

markman123 added a commit to markman123/toml that referenced this issue Oct 15, 2020
MarcoTrevisiol pushed a commit to MarcoTrevisiol/toml that referenced this issue Jun 7, 2021
Time values with fractions of seconds were parsed wrongly, despite date
parsing was fine.
@MarcoTrevisiol
Copy link

There was also an incorrect parsing of the "secfrac" component into microseconds of time values. Now the expected output is achieved.

@pradyunsg pradyunsg added type: bug A confirmed bug or unintended behavior component: decoder Related to parsing in `toml.load` syntax: date/time Related to dates, times or datetimes labels Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: decoder Related to parsing in `toml.load` syntax: date/time Related to dates, times or datetimes type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants