@@ -606,12 +606,22 @@ public HtmlUnitScriptable createElement(final Object tagName) {
606606
607607 // but I have no idea what the browsers are doing
608608 // the following code is a wild guess that might be good enough for the moment
609+
610+ // April 2026
611+ // looks like the browsers using a more simple approach now
612+ // see
613+ // org.htmlunit.javascript.host.dom.DocumentTest.documentCreateElementValidTagNames()
614+ // org.htmlunit.javascript.host.dom.DocumentTest.documentCreateElementValidTagNames1000()
615+ // org.htmlunit.javascript.host.dom.DocumentTest.documentCreateElementValidTagNames2000()
616+ // org.htmlunit.javascript.host.dom.DocumentTest.documentCreateElementValidTagNames3000()
617+ // org.htmlunit.javascript.host.dom.DocumentTest.documentCreateElementValidTagNames4000()
618+
609619 final String tagNameString = JavaScriptEngine .toString (tagName );
610620 if (tagNameString .length () > 0 ) {
611621 final int firstChar = tagNameString .charAt (0 );
612- if (!( isLetter ( firstChar )
613- || ':' == firstChar
614- || '_' == firstChar ) ) {
622+ if (firstChar < 128
623+ && ! Character . isLetter ( firstChar )
624+ && firstChar != ':' && firstChar != '_' ) {
615625 if (LOG .isInfoEnabled ()) {
616626 LOG .info ("createElement: Provided string '" + tagNameString + "' contains an invalid character" );
617627 }
@@ -620,23 +630,29 @@ public HtmlUnitScriptable createElement(final Object tagName) {
620630 "createElement: Provided string '" + tagNameString + "' contains an invalid character" ,
621631 org .htmlunit .javascript .host .dom .DOMException .INVALID_CHARACTER_ERR );
622632 }
633+
623634 final int length = tagNameString .length ();
624635 for (int i = 1 ; i < length ; i ++) {
625636 final int c = tagNameString .charAt (i );
626- if (!(Character .isLetterOrDigit (c )
627- || ':' == c
628- || '_' == c
629- || '-' == c
630- || '.' == c )) {
631- if (LOG .isInfoEnabled ()) {
632- LOG .info ("createElement: Provided string '"
633- + tagNameString + "' contains an invalid character" );
637+ if (c < 128 ) {
638+ if (c == 0
639+ || c == 9
640+ || c == 10
641+ || c == 12
642+ || c == 13
643+ || c == ' '
644+ || c == '/'
645+ || c == '>' ) {
646+ if (LOG .isInfoEnabled ()) {
647+ LOG .info ("createElement: Provided string '"
648+ + tagNameString + "' contains an invalid character" );
649+ }
650+ throw JavaScriptEngine .asJavaScriptException (
651+ getWindow (),
652+ "createElement: Provided string '" + tagNameString
653+ + "' contains an invalid character" ,
654+ org .htmlunit .javascript .host .dom .DOMException .INVALID_CHARACTER_ERR );
634655 }
635- throw JavaScriptEngine .asJavaScriptException (
636- getWindow (),
637- "createElement: Provided string '" + tagNameString
638- + "' contains an invalid character" ,
639- org .htmlunit .javascript .host .dom .DOMException .INVALID_CHARACTER_ERR );
640656 }
641657 }
642658 }
@@ -677,15 +693,6 @@ else if (element instanceof HtmlSvg) {
677693 return jsElement ;
678694 }
679695
680- // our version of the Character.isLetter() without MODIFIER_LETTER
681- private static boolean isLetter (final int codePoint ) {
682- return ((((1 << Character .UPPERCASE_LETTER )
683- | (1 << Character .LOWERCASE_LETTER )
684- | (1 << Character .TITLECASE_LETTER )
685- | (1 << Character .OTHER_LETTER )
686- ) >> Character .getType (codePoint )) & 1 ) != 0 ;
687- }
688-
689696 /**
690697 * Creates a new HTML element with the given tag name, and name.
691698 *
0 commit comments