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

未关闭 适合新手
#394 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
backend

调研方向

从 src/lib/meta-fetcher.ts 中的 parseMetaTags() 及其解析器测试开始。检查注释是如何被剥离的,然后覆盖带属性且大小写混合的 script 元素,包括 JSON-LD 和多个 script。添加一个回归测试,证明 script 内的标签不会影响 title、meta 或 canonical 结果,而 script 外的标签仍按原样解析。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
8
派生
4
平均合并
8 小时 44 分钟
30 天内合并 PR
159

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codercops/ogcops 的其他 Issue

查看 codercops/ogcops 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。