Skip to content

Parser fails on OutOfOrderTable with leading whitespace #263

Closed

Description

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.

Activity

  1. frostming commented on Apr 27, 2023

    @frostming
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions