owainlewis/yaml

from-file can't handle files that contain multiple documents

brighid opened this issue · 3 comments

Because #'from-file uses SnakeYAML's .load method, it can only handle input files that contain exactly one YAML document. Files that contain multiple YAML documents are not tremendously common, but are 100% permitted by the spec and definitely exist in the wild — for example, the way that the Jekyll/Octopress CMS stores pages/posts. When #'from-file encounters a multi-document input file, it throws an error like the following.

ComposerException expected a single document in the stream
 in 'string', line 2, column 1:
    layout: post
    ^
but found another document
 in 'string', line 11, column 1:
    ---
    ^
  org.yaml.snakeyaml.composer.Composer.getSingleNode (Composer.java:110)

As a point of information, when SnakeYAML's .loadAll method is called with multi-document input, it returns a lazy sequence of parsed documents.

Thanks for this. I wouldn't have noticed the issue with multiple documents.

Sounds like .loadAll might be the way to go.

FIxed. Added a parse-documents method to the reader and also parse-string will return a list of parsed documents if it encounters a string with multiple docs. New version here https://clojars.org/io.forward/yaml. Let me know if you have any issues. Thanks

Awesome; thank you. :)