Skip to content

fix(core): convert multi-line tags in cleanBody#77

Open
abhay-codes07 wants to merge 1 commit into
dodopayments:mainfrom
abhay-codes07:fix/cleanbody-multiline-tags
Open

fix(core): convert multi-line tags in cleanBody#77
abhay-codes07 wants to merge 1 commit into
dodopayments:mainfrom
abhay-codes07:fix/cleanbody-multiline-tags

Conversation

@abhay-codes07

Copy link
Copy Markdown
Contributor

Summary

cleanBody replaced configured tags with a regex missing the dotAll flag, so a <Tag>…</Tag> whose content spanned multiple lines was left in the output as raw markup. This adds the s flag so multi-line tags are converted too.

Closes #76.

Changes

  • packages/core/src/text.ts: add the s (dotAll) flag to the tag-replacement regex. The match stays lazy (.*?), so it still stops at the first closing tag and does not merge two adjacent tags.
  • Added two tests: a multi-line tag is converted, and adjacent tags are not merged.

Type

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change
  • Spec change (requires bump in AEO_SPEC_VERSION)
  • Docs / examples / tooling only

Verification

  • bun run build passes
  • bun run test passes (core: 182 tests)
  • bun run typecheck passes
  • If touching examples: ran dualmark verify (no examples touched)
  • If touching /spec/: ran sync-spec (no spec files touched)

Changeset

  • Added a changeset (patch for @dualmark/core)

cc @thepushkaraj @aagarwal1012. Small core fix, keeps the existing single-line behavior identical.

The HTML-tag replacement regex in cleanBody lacked the dotAll flag, so a
tag whose content spanned multiple lines was never matched and its raw
markup leaked into the cleaned markdown. Add the s flag while keeping the
lazy quantifier so multi-line tags are converted and adjacent tags are not
merged.
Copilot AI review requested due to automatic review settings July 1, 2026 02:28
@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@abhay-codes07 is attempting to deploy a commit to the Dodo Payments Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes @dualmark/core’s cleanBody so configured HTML-ish tags (e.g. <Highlighted>…</Highlighted>) are correctly replaced even when their contents span multiple lines.

Changes:

  • Add the s (dotAll) flag to the tag-replacement regex in cleanBody so . matches newlines.
  • Add tests covering multi-line tag conversion and ensuring adjacent tags are not merged.
  • Add a changeset for a patch release of @dualmark/core.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/text.ts Updates the tag-replacement regex flags (adds dotAll) and documents the behavior.
packages/core/test/text.test.ts Adds regression tests for multi-line tag replacement and lazy matching across adjacent tags.
.changeset/cleanbody-multiline-tags.md Patch changeset documenting the bug fix for release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/text.ts
Comment on lines +77 to 78
const re = new RegExp(`<${tag}>(.*?)<\\/${tag}>`, "gs");
out = out.replace(re, `${marker}$1${marker}`);

@dodo-squirrels dodo-squirrels Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: fix(core): convert multi-line tags in cleanBody

Verdict: LGTM — approving.

Reviewed end-to-end and exercised locally.

Root cause (confirmed on main)

cleanBody built the tag-replacement regex as new RegExp(`<${tag}>(.*?)<\\/${tag}>`, "g") — no dotAll. Since . doesn't match newlines, a tag whose content spans multiple lines was never matched, so raw <Highlighted>…</Highlighted> (or any custom htmlTagReplacements tag) leaked into the "cleaned" markdown that AI clients consume. Verified main uses the "g" flag.

Fix verification

The one-char change to the "gs" flag is correct. The concern with dotAll + a greedy match would be over-matching across multiple tags, but the match stays lazy (.*?), so it still stops at the first closing tag. Exercised the important cases directly on the branch:

Case Result
single-line <Highlighted>this</Highlighted> see **this** ✓ (unchanged)
multi-line <Highlighted>multi\nline</Highlighted> **multi\nline** ✓ (the fix)
adjacent tags across newline <Em>a</Em>\n<Em>b</Em> *a*\n*b* ✓ (not merged)
adjacent multi-line tags *a\n1* mid *b\n2* ✓ (not merged)
empty <Highlighted></Highlighted> ****

The two added tests cover both the multi-line conversion and the lazy-across-multiple-tags guarantee — exactly the right coverage.

Tests

  • @dualmark/core text suite: 35/35 pass locally.

Minimal, well-scoped, correct comment, changeset present. No concerns.

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.

cleanBody leaks raw tags when a tag spans multiple lines

2 participants