fix: Ensure attributes are lowercased when checking (#1183)

* fix: Ensure attributes are lowercased when checking

* add changeset

* fix to lower case

* Apply formatting changes

---------

Co-authored-by: mydea <mydea@users.noreply.github.com>
This commit is contained in:
Francesco Novy
2026-04-01 12:00:00 +08:00
committed by GitHub
parent a539fd8f5b
commit ff54a2b097
6 changed files with 29 additions and 12 deletions

View File

@@ -21,6 +21,7 @@ import {
isNativeShadowDom,
getCssRulesString,
getInputType,
toLowerCase,
} from './utils';
let _id = 1;
@@ -32,12 +33,12 @@ 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 = toLowerCase(element.tagName);
if (tagNameRegex.test(processedTagName)) {
// if the tag name is odd and we cannot extract
@@ -222,8 +223,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) {
@@ -638,7 +639,7 @@ function serializeElementNode(
attributes[attr.name] = transformAttribute(
doc,
tagName,
attr.name,
toLowerCase(attr.name),
attr.value,
);
}