Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Ensure attributes are lowercased when checking
  • Loading branch information
mydea committed May 10, 2023
commit ccdbfc7401fc0913c340dd5cbe78ca37f77514ef
12 changes: 7 additions & 5 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ export function genId(): number {
return _id++;
}

function getValidTagName(element: HTMLElement): string {
function getValidTagName(element: HTMLElement): Lowercase<string> {
if (element instanceof HTMLFormElement) {
return 'form';
}

const processedTagName = element.tagName.toLowerCase().trim();
const processedTagName = element.tagName
.toLowerCase()
.trim() as Lowercase<string>;

if (tagNameRegex.test(processedTagName)) {
// if the tag name is odd and we cannot extract
Expand Down Expand Up @@ -222,8 +224,8 @@ function getHref() {

export function transformAttribute(
doc: Document,
tagName: string,
name: string,
tagName: Lowercase<string>,
name: Lowercase<string>,
value: string | null,
): string | null {
if (!value) {
Expand Down Expand Up @@ -638,7 +640,7 @@ function serializeElementNode(
attributes[attr.name] = transformAttribute(
doc,
tagName,
attr.name,
attr.name.toLowerCase() as Lowercase<string>,
attr.value,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ export default class MutationBuffer {
// overwrite attribute if the mutations was triggered in same time
item.attributes[attributeName] = transformAttribute(
this.doc,
target.tagName,
attributeName,
target.tagName.toLowerCase() as Lowercase<string>,
attributeName.toLowerCase() as Lowercase<string>,
value,
);
}
Expand Down