Closed Bug 964211 Opened 6 years ago Closed 6 years ago

InvalidCharacterError: String contains an invalid character when registering custom element

Categories

(Core :: DOM: Core & HTML, defect)

x86
macOS
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla30

People

(Reporter: sole, Assigned: wchen)

References

Details

I can't register custom elements because I get this totally unexpected error when calling document.register:

document.registerElement('colourful-button', { // <-- BOOM!
  extends: 'button',
  prototype: buttonPrototype
});


See the linked example for a live demonstration!
http://people.mozilla.org/~spenades/test_cases/document.register/

I'm using Firefox Nightly 20140126.
For comparison this works in Chrome Canary which has web components enabled now.
The code has:

5260   if (!StringBeginsWith(lcName, NS_LITERAL_STRING("x-"))) {
5261     rv.Throw(NS_ERROR_DOM_INVALID_CHARACTER_ERR);
5262     return nullptr;
5263   }

Pretty sure the spec draft required this behavior back when we implemented this....  It looks like it's since been changed to the behavior described at http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type which allows all NCNames that don't match a specific blacklist.  It's not clear to me why the change, since the new behavior effectively reserves all names containing "-" for custom element use, which seems a bit odd.
Oh, that would explain the "crash".

I was reading the explainer yesterday, it definitely only asks you to have a hyphen now. The "x-" requirement has been dropped AFAIK.
The implementation currently in the tree is a very old version of the spec. There are patches for an updated implementation in review right now (Bug 856140).
This works correctly in Nightly now. Many thanks to all of you who worked on this bug!
Closing bug :-)
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Assignee: nobody → wchen
Target Milestone: --- → mozilla30
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.