Skip to content

mdcode: reject non-list frontmatter tags - #294

Open
amirhormati wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
amirhormati:okf-tags-guard
Open

mdcode: reject non-list frontmatter tags#294
amirhormati wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
amirhormati:okf-tags-guard

Conversation

@amirhormati

Copy link
Copy Markdown
Collaborator

Problem

tags: in OKF frontmatter is meant to be a list. The Documents Layout does not
check that, and a JavaScript string is iterable, so a bare comma-separated
value is expanded into one Dataplex label per character.

tags: Stack Overflow, votes, posts, community in a real bundle file stored
this in Knowledge Catalog:

{" ": "true", ",": "true", "O": "true", "S": "true", "a": "true", "c": "true", ...}

No error, no warning. The entry looks fine locally and is corrupt in the
catalog.

Fix

parseMarkdown throws when tags is present and is not an array:

okf/bundles/stackoverflow/tables/votes.md: "tags" must be a list, got "Stack Overflow, votes, posts, community"

Coercing the string by splitting on commas is the other option. I did not take
it: a comma can legitimately appear inside a tag, so coercion silently invents
a different tag set than the author wrote. An error at parse time is cheap and
points at the file.

Two supporting details:

  • parseMarkdown gained an optional source parameter so the message can name
    the file. Its only caller, loadEntry, passes the entry path.
  • The outer condition moved from truthy to an explicit undefined/null check,
    so an empty-string tags is reported rather than skipped.

Verification

  • tags: a, b, c throws with the file name and the offending value.
  • A proper YAML list and frontmatter with no tags at all behave exactly as
    before.
  • bun test ./tests/libts/scenarios.ts: 17 pass, 0 fail.

Ordering

Land after #293. The eight stackoverflow bundle files fixed there are the ones
that trip this guard, so merging this first makes that bundle fail to push.

A JavaScript string is iterable, so `tags: a, b, c` was expanded into one
Dataplex label per character rather than three labels. Throw instead, naming
the file, so the author gets an error rather than silent corruption.

Splitting the string on commas would be the other option, but a comma can
appear inside a tag, so coercing guesses at a tag set the author did not write.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@google-cla

google-cla Bot commented Aug 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant