flyx / NimYAML

YAML implementation for Nim
https://nimyaml.org
Other
186 stars 36 forks source link

Crashes on incorrect YAML #129

Closed PMunch closed 1 year ago

PMunch commented 1 year ago

I was trying to use NimYAML to parse the frontmatter for a Markdown editor. The editor itself updates the output automatically as the user types. This means that the user is able to type things into the frontmatter as they go and the frontmatter is attempted updated for every step. The problem came when I tried to enter a string with quotes, the following YAML, although obviously incorrect, crashes my entire program instead of just throwing a YAML parsing error:

title: "

Since I can't catch the error I can't simply silently ignore the invalid frontmatter and I could never parse YAML in a safe manner without risking my program to quit..

flyx commented 1 year ago

Try with current head, which should fix this specific issue. You can now handle the YamlParserError that is raised from this.

NimYAML hasn't been thoroughly tested with garbage / incomplete input, so there may be other cases that are not caught properly. Report back if you find others.

PMunch commented 1 year ago

Works a treat, thanks a lot! I'll let you know if I discover more bugs