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

Đang mở Phù hợp với người mới
#394 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với parseMetaTags() trong src/lib/meta-fetcher.ts và các bài kiểm thử cho parser đó. Kiểm tra cách comment được loại bỏ, sau đó bổ sung trường hợp kiểm thử cho các phần tử script có thuộc tính và chữ hoa chữ thường xen kẽ, bao gồm JSON-LD và nhiều script. Thêm một bài kiểm thử hồi quy cho thấy các thẻ bên trong script không ảnh hưởng đến kết quả title, meta hoặc canonical, trong khi các thẻ bên ngoài script vẫn được phân tích như trước.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
8
Fork
4
Merge trung bình
8 giờ 44 phút
Pull request đã merge (30 ngày)
159

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của codercops/ogcops

Tất cả issue của codercops/ogcops

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.