toml icon indicating copy to clipboard operation
toml copied to clipboard

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

Open programmerjake opened this issue 4 years ago • 2 comments

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

programmerjake avatar Sep 08 '20 00:09 programmerjake

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

markman123 avatar Oct 15 '20 22:10 markman123

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

MarcoTrevisiol avatar Jun 07 '21 10:06 MarcoTrevisiol