Numeric product slugs abort artifact composition (hash() given int)

Đã đóng Phù hợp với người mới
#4,836 0 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
79/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ệ
php
Lĩnh vực
backend, testing

Hướng nghiên cứu

Bắt đầu tại ArtifactCompiler::runtimeDeclarationsFromFallbacks() quanh dòng 1533 và lần theo cách slug sản phẩm trở thành khóa trong $products. Kiểm tra các map khác trong hàm này được khóa theo slug hoặc route xem có cùng hiện tượng ép kiểu khóa thành số nguyên hay không, sau đó thêm fixture hồi quy với slug sản phẩm dạng số như 249. Công việc được xem là hoàn tất khi quá trình composition thành công và ID thực thể sản phẩm băm chuỗi slug.

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

Mô tả

bug

Summary

Artifact composition aborts with TypeError: hash(): Argument #2 ($data) must be of type string, int given when a captured product has a numeric slug.

ArtifactCompiler::runtimeDeclarationsFromFallbacks() keys $products by product slug. PHP stores a numeric-string key such as "199" as an int, so the later loop

foreach ($products as $productSlug => &$product) {
    $product['id'] = 'product:' . hash('sha256', $productSlug);

passes an int to hash() under strict_types=1 and the whole import fails in the compose phase (static_site_importer_direct_artifact_phase_failed). Same class as #3098.

Evidence

Square Online store whose product URLs end in numeric IDs (/product/<name>/249, /263, /264). Every one of 46 pages compiled; compose failed:

ArtifactCompiler.php:1533
#0 ArtifactCompiler.php(1533): hash('sha256', 199)
#1 ArtifactCompiler.php(478): ArtifactCompiler->runtimeDeclarationsFromFallbacks(Array, Array, 'website/index.h...', ...)
#2 StagedTransport.php(522): ArtifactCompiler->finalizeArtifact(...)
#3 StagedTransport.php(423): ArtifactCompiler->composeWithCssRuleTrees(...)

Reproduced with Static Site Importer 1.33.392 / php-transformer 0.45.264; the same lines are on trunk (v0.45.270). This matches a production import that failed during building on the same source.

Expected

A product whose slug is all digits composes like any other product; its entity id is product: + sha256 of the slug string.

Suggested fix

Treat slug keys as strings where they are read back (e.g. hash('sha256', (string) $productSlug)), and audit the other slug/route-keyed maps in the same function for the same int-key coercion. Regression fixture: a product grid fallback with one product whose slug is numeric (e.g. 249); compose succeeds and the product entity id is the hash of "249".


Filed by Claude (Anthropic) via Claude Code during the Data Liberation import loop; the stack trace was captured from a local reproduction.

Ngôn ngữ chính
PHP
Star
25
Fork
3
Merge trung bình
2 giờ 20 phút
Pull request đã merge (30 ngày)
934

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 Automattic/blocks-engine

Tất cả issue của Automattic/blocks-engine

Issue tương tự

Thêm issue về PHP

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.