Skip to content

doctor: scan post_content for stripped block-attribute escapes #24

Description

@Schmandarine

Follow-up to #22 / #23, which added the rule (/edit-block-content) but no way to find damage that already exists.

#22 documents how a scripted post_content edit silently strips one backslash level from a block's attribute JSON. The corruption is invisible to every existing check — it stays valid JSON, parse_blocks() parses it, ACF returns it, the template prints it. On the site where it happened it survived six weeks and a production deploy before a human spotted it in a PDF.

A deterministic scan would have caught it in seconds.

Proposal

Add a content check to brmbh doctor that scans posts for stripped-escape artifacts.

Detect, but only inside block delimiter comments (<!-- wp:… {…} -->) — scanning whole post_content would false-positive on ordinary prose:

Pattern Was
u00[0-9a-f]{2} not preceded by \ &, <, >, ", --
rn between a lowercase and an uppercase letter \r\n

Report post ID, post type, block name, and the attribute key — enough to repair by hand:

{
  "name": "content",
  "status": "warn",
  "note": "2 posts with stripped block-attribute escapes",
  "hits": [
    { "id": 73, "type": "page", "block": "acf/events-grid", "key": "events_0_body", "found": "u0026" }
  ]
}

warn, not fail — the environment works, the data is wrong.

Details worth deciding

  • Skip revisions by default (--include-revisions to opt in). On the affected site the live post had 2 hits and revisions had ~40 — the noise buries the signal.
  • Report only, no --fix. u0026& is a deterministic reversal, but rn\r\n is not: rn occurs in legitimate text. An agent offering to auto-repair here would eventually eat real content. The JSON payload should be precise enough to repair deliberately instead.
  • Works over --ssh — the existing doctor flag already reaches a remote WordPress, so the same check can audit staging and production, which is exactly where this damage hides. That's most of the value.
  • Runs via wp-cli, so it should degrade to skip (not fail) when wp-cli is absent, like the SCF check.

Why it belongs in doctor

Doctor is already the thing an agent runs before and after touching an environment, and it already returns a JSON envelope agents branch on. A rule an agent can check beats one it can only remember — same argument as the verify grep in #23, but covering damage that predates the rule.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agenticAgent-facing surfaceblocksACF block factorycli@brmbh/cli packageenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions