safe access tagName of form element
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -106,7 +106,7 @@ exports[`[html file]: form-fields.html 1`] = `
|
||||
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0\\" />
|
||||
<meta http-equiv=\\"X-UA-Compatible\\" content=\\"ie=edge\\" />
|
||||
<title>form fields</title>
|
||||
</head><body>
|
||||
</head> <body>
|
||||
<form>
|
||||
<label for=\\"text\\">
|
||||
<input type=\\"text\\" value=\\"1\\" />
|
||||
@@ -126,8 +126,12 @@ exports[`[html file]: form-fields.html 1`] = `
|
||||
<option value=\\"2\\" selected=\\"\\">2</option>
|
||||
</select>
|
||||
</label>
|
||||
</form><noscript>SCRIPT_PLACEHOLDER</noscript>
|
||||
</body></html>"
|
||||
<label>
|
||||
<input name=\\"tagName\\" />
|
||||
</label>
|
||||
</form>
|
||||
|
||||
<noscript>SCRIPT_PLACEHOLDER</noscript></body></html>"
|
||||
`;
|
||||
|
||||
exports[`[html file]: hover.html 1`] = `
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||
<title>form fields</title>
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body>
|
||||
<form>
|
||||
<label for="text">
|
||||
<input type="text">
|
||||
<input type="text" />
|
||||
</label>
|
||||
<label for="radio">
|
||||
<input type="radio">
|
||||
<input type="radio" />
|
||||
</label>
|
||||
<label for="checkbox">
|
||||
<input type="checkbox">
|
||||
<input type="checkbox" />
|
||||
</label>
|
||||
<label for="textarea">
|
||||
<textarea name="" id="" cols="30" rows="10"></textarea>
|
||||
@@ -28,14 +27,16 @@
|
||||
<option value="2">2</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<input name="tagName" />
|
||||
</label>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
</body>
|
||||
<script>
|
||||
document.querySelector('input[type="text"]').value = '1';
|
||||
document.querySelector('input[type="radio"]').checked = true;
|
||||
document.querySelector('input[type="checkbox"]').checked = true;
|
||||
document.querySelector('textarea').value = '1234';
|
||||
document.querySelector('select').value = '2';
|
||||
</script>
|
||||
|
||||
</script>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user