bug: mock-doc splits inline style at `;` inside url(), corrupting data-URI backgrounds
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
- 72/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ệ
- css, html, javascript, node.js, typescript
Hướng nghiên cứu
Bắt đầu trong packages/mock-doc/src/css-style-declaration.ts tại setter set cssText, nơi cssText.split(';') chạy vô điều kiện trước bước ghép lại hiện có bằng slice(1).join(':') cho các giá trị. Chạy script repro từ issue trước (MockDocument + parseHtmlToFragment từ @stencil/core/mock-doc) để thấy việc cắt cụt, sau đó xem các test spec mock-doc hiện có cho css-style-declaration để khớp phong cách của chúng. Hoàn thành nghĩa là các khai báo chỉ được tách tại dấu chấm phẩy cấp cao nhất bên ngoài dấu ngoặc và dấu nháy, sao cho ba kết quả đầu ra mong đợi trong issue (round-trip innerHTML, style.backgroundImage, và round-trip parseHtmlToFragment) đều đúng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
4.45.3 (also reproduced on main at f4fe940 and 5.0.0-rc.1 / v5 at 1ed1c6c)
Current Behavior
MockCSSStyleDeclaration's cssText setter splits declarations with cssText.split(';'), so a semicolon inside url(...) (such as ;base64, in a data URI) or inside quotes terminates the declaration early. The remainder of the data URI is dropped (or misparsed as the next property if it contains :), leaving an unclosed url( or quote in the serialized style attribute.
This affects:
renderToString()when hydrating HTML that contains inline data-URI styles (<div style="background: url(data:image/gif;base64,...) no-repeat; color: red">), emitting<div style="background: url(data:image/gif; color: red;">where the unclosedurl(also invalidatescolor: redin browsers.el.setAttribute('style', ...)andel.style.cssText = ...in components running under SSR ornewSpecPage().toEqualHtml()in spec tests: JSXstyle={{ backgroundImage: 'url(data:image/png;base64,...)' }}usesstyle.setProperty()and serializes intact on the live element, whereasparseHtmlToFragment()re-parses the expected HTML string throughcssTextand truncates it, sotoEqualHtml()fails even against the element's ownouterHTML.
Expected Behavior
MockCSSStyleDeclaration.cssText only splits declarations at top-level semicolons (outside parentheses and quotes), matching browser CSSStyleDeclaration behavior and CSS Syntax Module Level 3:
doc.body.innerHTMLpreserves<div style="background: url(data:image/gif;base64,R0lGOD==) no-repeat; color: red;">x</div>.div.style.backgroundImageisurl('data:image/png;base64,iVBORw0KGgo=')anddiv.getAttribute('style')isbackground-image: url('data:image/png;base64,iVBORw0KGgo='); color: red;.parseHtmlToFragment(rendered.outerHTML)round-tripsbackground-image: url(data:image/png;base64,iVBORw0KGgo=); color: blue;unchanged.
System Info
System: node 26.13.0
Platform: linux (6.1.0-54-cloud-amd64)
CPU Model: Intel(R) Xeon(R) CPU @ 2.80GHz (64 cpus)
Stencil: 4.45.3
TypeScript: 5.8.3
Rollup: 4.44.0
Parse5: 7.2.1
jQuery: 4.0.0-pre
Terser: 5.37.0
Steps to Reproduce
Run npm install @stencil/[email protected] && node stencil-core-tslib.repro.mjs:
// stencil-core-tslib.repro.mjs
import { MockDocument, parseHtmlToFragment } from "@stencil/core/mock-doc";
const doc = new MockDocument(
'<div style="background: url(data:image/gif;base64,R0lGOD==) no-repeat; color: red">x</div>'
);
console.log(doc.body.innerHTML);
const div = doc.createElement("div");
div.setAttribute("style", "background-image: url('data:image/png;base64,iVBORw0KGgo='); color: red");
console.log(div.getAttribute("style"));
console.log(div.style.backgroundImage);
const rendered = doc.createElement("div");
rendered.style.setProperty("background-image", "url(data:image/png;base64,iVBORw0KGgo=)");
rendered.style.setProperty("color", "blue");
console.log("before parse:", rendered.outerHTML);
console.log("after parse: ", parseHtmlToFragment(rendered.outerHTML).firstElementChild.outerHTML);
Actual output:
<div style="background: url(data:image/gif; color: red;">x</div>
background-image: url('data:image/png; color: red;
url('data:image/png
before parse: <div style="background-image: url(data:image/png;base64,iVBORw0KGgo=); color: blue;"></div>
after parse: <div style="background-image: url(data:image/png; color: blue;"></div>
Code Reproduction URL
https://gist.github.com/trackoor/624030cdd797e27d114e86126108b278
Additional Information
In src/mock-doc/css-style-declaration.ts (packages/mock-doc/src/css-style-declaration.ts on v5), set cssText already rejoins : segments via splt.slice(1).join(':') so URLs with schemes survive, while the outer cssText.split(';') splits unconditionally.
Credit: https://ucsbplse.github.io/
- Ngôn ngữ chính
- TypeScript
- Star
- 13.2k
- Fork
- 865
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 29
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của stenciljs/core
-
bug(mock-doc): `Element.toggleAttribute()` is missing, so components that use it fail during SSRĐang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Stencil FOUC styles should use @layer to avoid cascade conflicts with React 19Có thể đã có người làm @johnjenkins đã nhận 230 ngày trước. Đang mởStencil v5
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
stenciljs/core#7016 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của stenciljs/core
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AykutSarac/jsoncrack.com#616 ·
-
nip27: long hashtag swallows the rest of the content, lone # gives an empty hashtagCó thể đã có người làm @bardrop đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
nbd-wtf/nostr-tools#578 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
backnotprop/plannotator#3427 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
microsoft/Power-CAT-Copilot-Studio-Kit#942 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: Duplicate preposition in heading and unformatted feedback text on Strengthen Argument pageĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AOSSIE-Org/DebateAI#801 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày