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

Aberta Para iniciantes
#394 3 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
84/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
typescript
Domínio
backend

Direção de pesquisa

Comece por parseMetaTags() em src/lib/meta-fetcher.ts e pelos testes desse parser. Verifique como os comentários são removidos e, em seguida, cubra elementos script com atributos e mistura de maiúsculas e minúsculas, incluindo JSON-LD e vários scripts. Adicione um teste de regressão mostrando que as tags dentro de scripts não afetam os resultados de title, meta ou canonical, enquanto as tags fora dos scripts são analisadas como antes.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
TypeScript
Estrelas
8
Forks
4
Merge médio
8h 41min
PRs com merge (30d)
157

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de codercops/ogcops

Todas as issues de codercops/ogcops

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.