fix(browser): keep the first DOM attribute when the name is repeated (#1516)
* fix(browser): keep the first DOM attribute when the name is repeated 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 #1496 * fix(browser): preserve case-sensitive DOM attribute names * test(browser): align repeated attribute coverage with deduplication --------- Co-authored-by: taljeri <318237806+taljeri@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
taljeri
morluto
parent
4d8d76b253
commit
f6009d0077
@@ -177,15 +177,24 @@ export const captureDom = (
|
||||
const parent = Math.trunc(parents[index] ?? -1);
|
||||
const nodeIndex = nodes.length;
|
||||
const nodeName = indexedString(strings, nodeNames[index]);
|
||||
const rawAttributeNames = attributeIndexes
|
||||
.filter((_value, attributeIndex) => attributeIndex % 2 === 0)
|
||||
.map((value) => indexedString(strings, value));
|
||||
const seenAttributeNames = new Set<string>();
|
||||
const attributeNames: string[] = [];
|
||||
for (const name of rawAttributeNames) {
|
||||
if (!seenAttributeNames.has(name)) {
|
||||
seenAttributeNames.add(name);
|
||||
attributeNames.push(name);
|
||||
}
|
||||
}
|
||||
nodes.push({
|
||||
index: nodeIndex,
|
||||
parent_index: parent < 0 ? -1 : baseIndex + parent,
|
||||
node_type: Math.max(0, Math.trunc(nodeTypes[index] ?? 0)),
|
||||
node_name: nodeName,
|
||||
node_value_length: indexedString(strings, nodeValues[index]).length,
|
||||
attribute_names: attributeIndexes
|
||||
.filter((_value, attributeIndex) => attributeIndex % 2 === 0)
|
||||
.map((value) => indexedString(strings, value)),
|
||||
attribute_names: attributeNames,
|
||||
});
|
||||
const metadata = domMetadata({
|
||||
strings,
|
||||
@@ -385,7 +394,8 @@ const domMetadata = (
|
||||
} = options;
|
||||
const pairs = new Map<string, string>();
|
||||
for (let index = 0; index + 1 < attributes.length; index += 2) {
|
||||
const name = indexedString(strings, attributes[index]).toLowerCase();
|
||||
// Chrome already folds HTML names; SVG/XML names remain case-sensitive.
|
||||
const name = indexedString(strings, attributes[index]);
|
||||
const value = indexedString(strings, attributes[index + 1]);
|
||||
// HTML keeps the first declaration. A later repeat must not move dom_urls.
|
||||
if (!pairs.has(name)) pairs.set(name, value);
|
||||
|
||||
Reference in New Issue
Block a user