Skip to content

fix: keep apostrophes and decode html entities in meta tags - #134

Merged
anurag629 merged 1 commit into
codercops:devfrom
prakashNalla:fix/meta-tag-entities
Oct 15, 2026
Merged

anurag629 merged 1 commit into
codercops:devfrom
prakashNalla:fix/meta-tag-entities

Conversation

@prakashNalla

Copy link
Copy Markdown
Contributor

Description

parseAttributes now matches each value up to the same quote it opened with, so content="Don't Panic" and content='The "best" guide' come back in full. decodeEntities is a single pass over named entities (&, <, >, ", ',  ) plus decimal and hex numeric ones, so < becomes < and unknown entities are left as they are. parseMetaTags is exported and the placeholder test is replaced with real cases.

Closes #106

How I Tested This

  • npm ci, npm run check (0 errors, 0 warnings, 10 existing hints), npm run test (19 files / 242 tests pass), npm run build, all on Node v22.23.3
  • Ran the new parseMetaTags tests against the old parser (with only the export added): 7 of the 8 fail. The unknown-entity case passes on both.
  • npm run dev, then /api/preview with the Wikipedia link from the issue returns "ogTitle":"The Hitchhiker's Guide to the Galaxy - Wikipedia" (the live site still returns ').

AI Assistance

Claude helped me understand the issue & I wrote the fix & tests.

Type of Change

  • Bug fix
  • Tests

Screenshots

N/A, parser change. Covered by the new tests and the /api/preview output above.

Checklist

  • This PR targets dev
  • I was assigned the linked issue
  • npm run check passes
  • npm run test passes
  • For a bug fix: the new test fails without my change
  • Tested locally with npm run dev
  • Screenshots included for visual changes
  • New templates follow the Template Guidelines

Quoted values stopped at the first quote of either kind, and only six named entities were decoded, so titles like the Wikipedia one showed a raw &codercops#39;.

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @prakashNalla, this covers all of #106, and fast too. I merged it onto current dev: npm run check is clean, all 242 tests pass, and against the old parser with only the export added, 7 of your 8 new tests fail. The unknown entity one passes either way, like you wrote. Merging.

@anurag629 anurag629 added the hacktoberfest-accepted PR counts for Hacktoberfest label Oct 15, 2026
@anurag629
anurag629 merged commit e317024 into codercops:dev Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted PR counts for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep apostrophes and decode HTML entities when parsing meta tags

2 participants