Preview checker: `<meta>` tags inside a `<script>` string override the real ones

Offen Anfängerfreundlich
#394 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
84/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
typescript
Bereich
backend

Rechercherichtung

Beginne mit parseMetaTags() in src/lib/meta-fetcher.ts und den Tests für diesen Parser. Prüfe, wie Kommentare entfernt werden, und ergänze Tests für Script-Elemente mit Attributen und gemischter Groß- und Kleinschreibung, einschließlich JSON-LD und mehreren Scripts. Füge einen Regressionstest hinzu, der zeigt, dass Tags innerhalb von Scripts die Ergebnisse für Titel, Meta und Canonical nicht beeinflussen, während Tags außerhalb von Scripts wie bisher geparst werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug good first issue

parseMetaTags() in src/lib/meta-fetcher.ts strips HTML comments before it looks for tags (#389), but it still reads tags out of <script> contents. In HTML a script's contents are plain text, so a browser never sees tags written inside a JavaScript string, but the checker does, and a later meta tag overwrites an earlier one:

parseMetaTags(`
  <meta property="og:title" content="Pricing | Acme">
  <script>const share = '<meta property="og:title" content="Untitled">';</script>
`, 'https://example.com').ogTitle
// "Untitled"

It goes the other way for the tags where the first one wins: a <title> or <link rel="canonical"> inside a script before the real ones is picked instead, so a page gets Draft and https://acme.dev/draft instead of Pricing | Acme and https://acme.dev/pricing.

What to do

  • Remove <script> elements with their contents (any attributes, any case) right after the comments are stripped, so everything below works on HTML without them. A non-greedy match up to the first </script> is enough, since that's where HTML ends a script too.

Acceptance criteria

  • A <title>, <meta> or <link> inside a <script>, before or after the real tag, never changes the result
  • Tags outside scripts parse the same as today, including a page with several scripts and a <script type="application/ld+json">
  • A test that fails on the current code
  • npm run check, npm run test and npm run build pass

Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #NUM in the description.

Vorherrschende Sprache
TypeScript
Sterne
8
Forks
4
Ø Merge
8 Std. 44 Min.
Gemergte PRs (30 T.)
159

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus codercops/ogcops

Alle Issues in codercops/ogcops

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.