preaction / Statocles

Static website CMS
http://preaction.me/statocles
Other
84 stars 33 forks source link

Link objects are incorrectly serialized in Statocles Documents #522

Open preaction opened 7 years ago

preaction commented 7 years ago

When we take a bunch of Statocles::Link objects and serialize them in the markdown file, they appear like so:

---
links:
  canonical:
    - !!perl/hash:Statocles::Link
      href: http://blogs.perl.org/users/preaction/2016/11/beamemitter-v1004-released.html
---

YAML has a special syntax to serialize objects, the !!perl/<reftype>:<class> syntax. Instead of allowing this, we should serialize it into a plain hash or a simple string ourselves.

This happens when we run statocles blog post with the EDITOR variable set in our environment, type in our link and our post, and then quit our editor. Statocles loads the document we wrote (which inflates the Statocles::Link objects), adds the things it needs, generates the post slug and directory, and then re-writes the document back out. When it writes the document back out, it passes in the Statocles::Link objects directly to YAML, which creates the YAML-serialized !!perl/hash:Statocles::Link thing.

The routine that performs this serialization is Statocles::Store::_freeze_document. This routine is where this bug needs to be fixed.