Expand what is considered to be a valid tag name to include underscores: (#41)

- was making this change for <wix-image> on Wix websites, but discovered after that this has already been done in e4593ff76d
 - have tested document.createElement('wix-image') and document.createElement('foo_bar'), but can't find a canonical source for what is allowed in tag names.
 - this restriction was originally introduced in #150 to prevent document.createElement('alt=""') i.e. a very malformed tag name
This commit is contained in:
Eoghan Murray
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 949c236e29
commit cd601571ea

View File

@@ -9,7 +9,7 @@ import {
} from './types';
let _id = 1;
const symbolAndNumberRegex = RegExp('[^a-z1-6-]');
const tagNameRegex = RegExp('[^a-z1-6-_]');
function genId(): number {
return _id++;
@@ -18,7 +18,7 @@ function genId(): number {
function getValidTagName(tagName: string): string {
const processedTagName = tagName.toLowerCase().trim();
if (symbolAndNumberRegex.test(processedTagName)) {
if (tagNameRegex.test(processedTagName)) {
// if the tag name is odd and we cannot extract
// anything from the string, then we return a
// generic div