Skip to content

Invalid serialization after removal of array itemΒ #405

Closed

Description

@DimmaDont

When an item containing whitespace before the comma is removed from an array, it serializes incorrectly:

>>> from tomlkit import parse
>>> doc = parse('x = [\n    "foo" ,#spam\n    "bar",\n]')
>>> doc['x'].remove('foo')
>>> docstr = doc.as_string()
>>> print(docstr)
x = [,#spam
    "bar",
]
>>> parse(docstr)
Traceback (most recent call last):
  File "<python-input-5>", line 1, in <module>
    parse(docstr)
    ~~~~~^^^^^^^^
  File "W:\tomlkit\tomlkit\api.py", line 91, in parse
    return Parser(string).parse()
           ~~~~~~~~~~~~~~~~~~~~^^
  File "W:\tomlkit\tomlkit\parser.py", line 139, in parse
    item = self._parse_item()
  File "W:\tomlkit\tomlkit\parser.py", line 238, in _parse_item
    return self._parse_key_value(True)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "W:\tomlkit\tomlkit\parser.py", line 331, in _parse_key_value
    val = self._parse_value()
  File "W:\tomlkit\tomlkit\parser.py", line 435, in _parse_value
    return self._parse_array()
           ~~~~~~~~~~~~~~~~~^^
  File "W:\tomlkit\tomlkit\parser.py", line 608, in _parse_array
    raise self.parse_error(UnexpectedCharError, self._current)
tomlkit.exceptions.UnexpectedCharError: Unexpected character: ',' at line 1 col 5
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