Skip to content

A complex (sequence or mapping) YAML key is rewritten as the literal text "System.Collections.Generic.List`1[System.Object]" #208

Closed

Description

@matt-edmondson

What's wrong

YamlSerializer.TryParseYamlObject turns every key into a string with pair.Key.ToString() (Frontmatter/YamlSerializer.cs:96). Nested mappings do the same via kvp.Key?.ToString() (:197, and in DeepCloneValue at :158). A YAML complex key deserializes to a List<object> or Dictionary<object, object>, whose ToString() is the .NET type name. The original key is lost, and every write path then saves that type name back into the document.

Failure scenario (verified against current main)

---
? [a, b]
: c
title: t
---
body
  • ExtractFrontmatter returns the key System.Collections.Generic.List`1[System.Object].
  • CombineFrontmatter writes System.Collections.Generic.List`1[System.Object]: c.
  • AddFrontmatter(doc, {draft: true}) writes the same corrupted key and adds draft: true.
  • ? {x: 1} becomes System.Collections.Generic.Dictionary`2[System.Object,System.Object]: c.
  • The same happens for a complex key nested under another key, e.g. meta: { ? [1, 2] : pair }.

Suggested fix

When any key, at any depth, is not a scalar, treat the block as unreadable (return false). That reuses the existing "leave unreadable frontmatter alone" path in CombineFrontmatter and AddFrontmatter instead of inventing a string form.

Acceptance criteria

  • CombineFrontmatter and AddFrontmatter return a document with a complex key unchanged.
  • No output ever contains a .NET type name as a key.

Activity

  1. added
    bug
    on Oct 19, 2026
  2. matt-edmondson commented on Oct 20, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    • Category: Bug
    • Priority: Medium. Complex YAML keys are rare in frontmatter, but when one is present every write path (CombineFrontmatter, AddFrontmatter) silently replaces the original key with a .NET type name. That corrupts the document.
    • Area / suggested assignee: Frontmatter/YamlSerializer.cs: TryParseYamlObject (:96), the nested-mapping conversion (:197), and DeepCloneValue (:158). Owner: @matt-edmondson
    • Duplicates / in progress: not a duplicate. The open PRs Treat a header with no keys as empty so AddFrontmatter fills it [patch] #207 (empty header) and Double-quote strings holding a carriage return or NEL so they round-trip [patch] #205 (CR/NEL quoting) touch the same serializer but not key handling, so a fix may conflict lightly with them.
    • Next step: the suggested fail-closed fix is right. Return false when any key at any depth is not a scalar, so the existing "leave unreadable frontmatter alone" path handles it. Add tests for a top-level sequence key, a top-level mapping key, and a nested complex key.

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions