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

Parser fails on OutOfOrderTable with leading whitespace #263

Closed
ghost opened this issue Jan 24, 2023 · 1 comment
Closed

Parser fails on OutOfOrderTable with leading whitespace #263

ghost opened this issue Jan 24, 2023 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 24, 2023

The tomlkit parser fails on the following valid TOML document:

 [[a.b.c]]  # note: this line starts with a space character
[a.b]

For example:

>>> import tomlkit
>>> tomlkit.parse(" [[a.b.c]]\n[a.b]")

Traceback (most recent call last):
  File "env\Lib\site-packages\tomlkit\parser.py", line 165, in parse
    body.append(key, value)
  File "env\Lib\site-packages\tomlkit\container.py", line 262, in append
    current.append(k, v)
  File "env\Lib\site-packages\tomlkit\items.py", line 1600, in append
    m = re.match("(?s)^([^ ]*)(.*)$", _item.trivia.indent)
                                      ^^^^^^^^^^^^
AttributeError: 'OutOfOrderTableProxy' object has no attribute 'trivia'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "env\Lib\site-packages\tomlkit\api.py", line 83, in parse
    return Parser(string).parse()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "env\Lib\site-packages\tomlkit\parser.py", line 167, in parse
    raise self.parse_error(ParseError, str(e)) from e
tomlkit.exceptions.ParseError: 'OutOfOrderTableProxy' object has no attribute 't
rivia' at line 2 col 5

The problem disappears if the leading whitespace is removed from the first line.

This issue applies to the latest commit 6512eaa on master as well as the latest release v0.11.6.

I'm experimenting with a TOML fuzzer which revealed this issue. I guess most normal applications are not likely to hit this case, so I understand if this gets low priority. It still seems worthwhile to fix it though.

@frostming
Copy link
Contributor

frostming commented Apr 27, 2023

This issue seems not existing on the master branch. (Probably by #284 )

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

No branches or pull requests

1 participant