rubyyamljekyllyaml-front-matter

Ruby has problem with single file trying to parse YAML (frontmatter) from Jekyll project


So I am successfully parsing frontmatter with

YAML.load_file(stringForFilePath, permitted_classes: ['Date'])

on a whole bunch of files except on a single file I get this error:

control characters are not allowed at line 1 column 1 (Psych::SyntaxError)

Things I have tried:

  1. Putting the frontmatter / YAML in a validator to check for errors
  2. Deleting the entire frontmatter and put in a basic stub in its place.
  3. Checked the file encoding (UTF-8 same as other files that are working)
  4. Checked the line endings (CLRF same as other files that are working)
  5. Removing every non-ASCII character from the file (e.g. the HTML, there was none in frontmatter)

Solution

  • Problem was with a non-printing/invisible control character in my HTML body that was very hard to track down. Some 3rd party tools I tried didn't pick it up and it wasn't until I updated my text editor was I finally able to find it.