Repository navigation
fix(browser): keep the first DOM attribute when the name is repeated - #1516
Conversation
When an element in a captured DOM tree carries duplicate attribute declarations (e.g. repeated href, action, or src), domMetadata folded the attributes into a Map using pairs.set(), overwriting earlier declarations with the last one. HTML specifies that the first declaration is kept when an attribute name is repeated. This aligns domMetadata and attribute_names to retain the first occurrence case-insensitively, matching HTML and ensuring that attribute_names and dom_urls reflect the same attributes. Fixes morluto#1496
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: Main already has the URL half of this change since Live pagesHTML markup never gets this far, because the parser drops a repeated name. Two
Chromium picks the attribute whose name is The last row is wrong on every build. Chromium makes no link from Tests
The PR's Not runEdit: I tested most of this list after the merge. The results are in #1516 (comment). The scenario item was wrong: that artifact is
Thanks, taljeri, for the fix and the regression test. Test pages<!-- dup.xhtml, served as application/xhtml+xml -->
<a id="x1" href="/good-x1" HREF="/bad-x1">lower first</a>
<a id="x2" HREF="/bad-x2" href="/good-x2">upper first</a>
<!-- ns.html -->
<a id="n1" href="/good-n1">lower first</a>
<a id="n2">upper first</a>
<script>
document.getElementById("n1").setAttributeNS(null, "HREF", "/bad-n1");
const n2 = document.getElementById("n2");
n2.setAttributeNS(null, "HREF", "/bad-n2");
n2.setAttribute("href", "/good-n2");
</script>Commandsnpm ci && npm run build
rea inspect-web-page http://127.0.0.1:9335 <target> --format json
node scripts/run-development-tests.mjs focused \
src/browser/CdpCaptureDocuments.baseUrl.test.ts \
src/browser/CdpCaptureDocuments.test.ts
patch -p1 < 1516.diff # on a scratch copy of 46c9cba03Test setup
🤖 Generated with Claude Code (Opus 5.5) 🦊 |
# Conflicts: # src/browser/CdpCaptureDocuments.ts
|
Thanks @taljeri for catching repeated DOM attributes and preserving the first declaration! Squash merged with the review fixes for case-sensitive attributes. Welcome to REA, and thank you for your first PR. |
|
TL;DR: The merge fixed what I found about repeated names. REA now follows the same value as Chromium when Results after the mergeMy earlier comment said the scenario DOM artifact uses I reran every case from my earlier comment in Chromium 154 (BSD-3-Clause). I built
In my test pages, the lowercase name holds the good value and the uppercase name holds the bad one. "Uppercase name first" covers
This is one file, not the two from my earlier comment. The test I said failed, "keeps the first value when an attribute name repeats", now expects Still not run
Thanks, morluto, for the review fix that stops lowercasing names. It made the uppercase rows right. Per-page countsElements whose
The Also checked on Commandsrea inspect-web-page http://127.0.0.1:<port> <target> --format json
rea capture-browser-scenario scenario.json --format json
node scripts/run-development-tests.mjs focused \
src/browser/CdpCaptureDocuments.baseUrl.test.tsTest pages added since my last comment<!-- mixed.html: HTML with uppercase names in the source -->
<LINK ID="l3" REL="stylesheet" Rel="mcp" HREF="/good-l3.css">
<A ID="a1" HREF="/good-a1" Href="/bad-a1">upper then mixed</A>
<svg width=10 height=10><A ID="s1" HREF="/good-s1" href="/bad-s1"><text>s1</text></A></svg>
<math><mi id="m1" HREF="/good-m1">x</mi></math>
<!-- extra.html -->
<svg xmlns:xlink="http://www.w3.org/1999/xlink">
<image id="im1" xlink:href="/xl-image.png" width="1" height="1"/>
<use id="u1" xlink:href="#g0"/>
</svg>Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
Summary
Fixes #1496
Page capture lists DOM attributes and computes URLs/hints from them. When an element carried duplicate attribute declarations (e.g. repeated
href,action, orsrc),domMetadatafolded them into a Map withpairs.set(), causing later duplicate values to overwrite earlier ones.In HTML, the first declaration is kept when an attribute name is repeated. This aligns
domMetadataandattribute_namesto preserve the first occurrence case-insensitively, ensuring thatattribute_namesanddom_urlsdescribe the same attributes according to HTML rules.Changes
src/browser/CdpCaptureDocuments.ts, keep the first attribute occurrence indomMetadatausingif (!pairs.has(name)) pairs.set(...).attribute_nameson each node by case-insensitive first appearance.src/browser/CdpCaptureDocuments.baseUrl.test.ts.Verification
npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.ts src/browser/CdpCaptureDocuments.test.ts(all passed)npm run check:fast(typecheck & lint clean)npm run docs:check(clean metadata contracts)