Bug 25893

Summary: createElement should support passing markup instead of just element name, e.g. document.createElement("<select readonly>")
Product: WebKit Reporter: Lúcio Flávio Corrêa <lucio.correa>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED CONFIGURATION CHANGED    
Severity: Normal CC: ahmad.saleem792, ap, bfulgham, enqd, evan, ian, lucio.correa, Ms2ger, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   

Description Lúcio Flávio Corrêa 2009-05-20 10:46:51 PDT
Hey Guys. I'm trying to access a website (www.minhacasaminhavida.pe.gov.br) but webkit based browsers doesn't work with that. This is the message returned by WebInpector:

INVALID_CHARACTER_ERR: DOM Exception 5
HTMLComponents.js:1962Error: INVALID_CHARACTER_ERR: DOM Exception 5

The file location is http://www.minhacasaminhavida.pe.gov.br/pmc/components/HTMLComponents.js

Thanks in Advance
Comment 1 Lúcio Flávio Corrêa 2009-05-20 15:27:12 PDT
(In reply to comment #0)
> Hey Guys. I'm trying to access a website (www.minhacasaminhavida.pe.gov.br) but
> webkit based browsers doesn't work with that. This is the message returned by
> WebInpector:
> 
> INVALID_CHARACTER_ERR: DOM Exception 5
> HTMLComponents.js:1962Error: INVALID_CHARACTER_ERR: DOM Exception 5
> 
> The file location is
> http://www.minhacasaminhavida.pe.gov.br/pmc/components/HTMLComponents.js
> 
> Thanks in Advance
> 

Ah, forgot to add that it works in Firefox and IE too.
Comment 2 Alexey Proskuryakov 2009-05-21 05:50:54 PDT
Believe it or not, but Firefox successfully creates a SELECT element with document.createElement("<select>"). IE has a separate code path.
Comment 3 Eric Seidel (no email) 2009-05-21 05:53:04 PDT
Seems we should file a bug with mozilla.
Comment 4 Alexey Proskuryakov 2009-05-21 06:00:01 PDT
IE even supports document.createElement("<select readonly>"), but Firefox does not.

My guess is that Firefox had to partially implement this IE quirk for web compatibility.
Comment 5 Alexey Proskuryakov 2010-08-30 10:25:46 PDT
*** Bug 44841 has been marked as a duplicate of this bug. ***
Comment 6 Alexey Proskuryakov 2010-08-30 10:27:37 PDT
Another example of a broken site in duplicate bug.
Comment 7 Evan Martin 2011-01-04 15:29:31 PST
Alexey's guess in comment 4 is correct:

Mozilla bug discussing the problem:
https://bugzilla.mozilla.org/show_bug.cgi?id=489532

Diff showing they added angle brackets:
http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/content/html/document/src/nsHTMLDocument.cpp&rev=3.791&mark=1459,1467-1473#1458

But it looks like they removed it in 2004:
http://hg.mozilla.org/mozilla-central/rev/ecdf587c02d0
Comment 8 Alexey Proskuryakov 2011-01-04 16:03:24 PST
> But it looks like they removed it in 2004:
> http://hg.mozilla.org/mozilla-central/rev/ecdf587c02d0

In fact, that's July 2010, just weird date formatting.

If Mozilla won't reconsider removing this quirk before shipping Firefox 4, we almost certainly don't want to add it.
Comment 9 Ms2ger (he/him; ⌚ UTC+1/+2) 2011-01-05 02:02:07 PST
I don't think Mozilla will add this quirk back. (At least, I'll do what I can to avoid it.)

Lúcio, any chance you could contact the website? The changes they need to make come down to changing document.createElement("<img>") to document.createElement("img"). (The ones that are guarded by isIE checks are probably not problematic.)
Comment 10 Ahmad Saleem 2022-08-05 10:06:07 PDT
The test case from Mozilla Bug mentioned in Comment 07 behaves same across all browsers:

Link - http://software.hixie.ch/utilities/js/live-dom-viewer/?%3Cscript%3Ew%28document.createElement%28%22%3Cx%3E%22%29%29%3C%2Fscript%3E

** Safari 15.6 on macOS 12.5 **

error: InvalidCharacterError: The string contains invalid characters. on line 1
rendering mode: BackCompat
document has no title

** Firefox Nightly 105 **

error: InvalidCharacterError: String contains an invalid character on line 1

rendering mode: BackCompat

document has no title

** Chrome Canary 106 **

error: Uncaught InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('<x>') is not a valid name. on line 1
rendering mode: BackCompat
document has no title

____

Since all browsers are now matching with each other, I am going to mark this as "RESOLVED CONFIGURATION CHANGED". Please reopen, if I have mark it as wrong. Thanks!