garcia / simfile

A modern simfile parsing & editing library for Python 3
MIT License
62 stars 7 forks source link

Leading text in file causes exception #41

Closed zaneneuschuler closed 1 year ago

zaneneuschuler commented 1 year ago

While using nine or null, for one particular file it would not be able to load. After looking through the files I found the issue:

[2023-06-29 21:37:37.085] ERROR    stray 'x' encountered at start of document
Traceback (most recent call last):
  File "nine_or_null\__init__.py", line 729, in batch_process
  File "simfile\__init__.py", line 109, in open
  File "simfile\__init__.py", line 152, in open_with_detected_encoding
  File "simfile\__init__.py", line 83, in load
  File "simfile\base.py", line 164, in __init__
  File "simfile\ssc.py", line 217, in _parse
  File "msdparser\parser.py", line 103, in parse_msd
  File "msdparser\parser.py", line 72, in push_text

As it turns out, you can have leading text at the very top of a MSD file, and (at least tested on ITGMania, but this is such an edge case I wouldn't doubt it also works in sm5.1/etc) it will still be usable in game. However, since this is completely unexpected input from a proper file w/r/t this library, it throws an error.

garcia commented 1 year ago

This can be resolved on the application's side by opting into non-strict parsing (e.g. simfile.load(..., strict=False). I've mentioned this to the maintainer and they said it would be fixed in the next release.