Skip to content

Aggressive/Maximum merging swaps the values of two keys that normalize alike (e.g. related / page_related) instead of merging them #131

Description

@matt-edmondson

What's wrong

In FindBasicCanonicalName (Frontmatter/PropertyMerger.cs, around lines 219–233), the exact-normalized-match loop maps each key to the other key in its equivalence class. With related and page_related:

  • related → page_related
  • page_related → related

MergeSimilarProperties then groups by canonical name and gets two single-key groups instead of one merged group. MergeArrayValues (around line 189) writes each group under the other key's name.

Failure scenario (reproduced in a fresh process)

input = "---\nrelated:\n- a\npage_related:\n- b\n---\nBody\n"
SortAndStandardize(input, AsIs, AsIs, Aggressive)

Output: page_related: [a] and related: [b]. The values are swapped, and nothing is merged.

With scalar values the two keys never merge either. So for this whole class of keys, the documented Aggressive/Maximum behaviour (merging redundant properties) does nothing, and for lists it corrupts which value belongs to which key.

Suggested fix

Pick one deterministic canonical name per equivalence class, so that every key in the class maps to the same target. For example:

  1. use the known mapping if there is one;
  2. otherwise use the unprefixed or shortest key;
  3. break any remaining tie ordinally.

As a safety net, a group with a single original key should keep that key's own name.

Acceptance:

  • the input above produces a single related: [a, b], or whichever canonical name is chosen, with both values;
  • a test covers the scalar case too.

Activity

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

Metadata

Metadata

Labels

readyFully specified; implement as written

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions