safe access tagName of form element
This commit is contained in:
Yanzhen Yu
2020-12-21 12:37:13 +08:00
parent b6ca577f3e
commit 1cc7164f2c
3 changed files with 75 additions and 66 deletions

View File

@@ -18,8 +18,12 @@ function genId(): number {
return _id++;
}
function getValidTagName(tagName: string): string {
const processedTagName = tagName.toLowerCase().trim();
function getValidTagName(element: HTMLElement): string {
if (element instanceof HTMLFormElement) {
return 'form';
}
const processedTagName = element.tagName.toLowerCase().trim();
if (tagNameRegex.test(processedTagName)) {
// if the tag name is odd and we cannot extract
@@ -223,7 +227,7 @@ function serializeNode(
blockClass,
blockSelector,
);
const tagName = getValidTagName((n as HTMLElement).tagName);
const tagName = getValidTagName(n as HTMLElement);
let attributes: attributes = {};
for (const { name, value } of Array.from((n as HTMLElement).attributes)) {
attributes[name] = transformAttribute(doc, name, value);