Closed Bug 1275832 Opened 9 years ago Closed 8 years ago

Implement custom element name validation for custom element

Categories

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

defect

Tracking

()

RESOLVED FIXED
mozilla52
Tracking Status
firefox52 --- fixed

People

(Reporter: jdai, Assigned: jdai)

References

Details

(Whiteboard: dom-ce-m1)

Attachments

(1 file, 5 obsolete files)

According to session 4.13.3 core concepts [1], we need to implement a function to validate custom element name. [1] https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name
(I'm marking all the Custom Elements bugs as "backlog" but that's just to indicate they're not something we're fixing urgently and no comment on priority or anything.)
Whiteboard: btpp-backlog
Assignee: nobody → jdai
Blocks: 1275835
Attached patch wip, v1 (obsolete) — Splinter Review
Attached patch wip, v2 (obsolete) — Splinter Review
Attachment #8773637 - Attachment is obsolete: true
Priority: -- → P2
Whiteboard: btpp-backlog → dom-ce-m1
Attachment #8788848 - Flags: feedback?(echen)
Comment on attachment 8788848 [details] [diff] [review] Bug 1275832 - Implement custom element name validation for custom elements. v1 Review of attachment 8788848 [details] [diff] [review]: ----------------------------------------------------------------- Spec says name must not be any of the following: annotation-xml, ::: dom/base/nsContentUtils.cpp @@ +2829,5 @@ > + // A valid custom element name is a sequence of characters name which > + // must match the PotentialCustomElementName production: > + // PotentialCustomElementName ::= [a-z] (PCENChar)* '-' (PCENChar)* > + const char16_t* name = aName->GetUTF16String(); > + if (name[0] < 'a' || name[0] > 'z') { We still run this check for empty string, it is not right. I think we should do some checks for empty string. @@ +2837,5 @@ > + int i = 1; > + int len = aName->GetLength(); > + bool hasDash = false; > + > + do { The name contains only one character, e.g. "a", will still run into this do-while, it is not right and necessary. Could we use while-loop or for-loop here? @@ +2838,5 @@ > + int len = aName->GetLength(); > + bool hasDash = false; > + > + do { > + if (name[i] >= 0xD800 && name[i] <= 0xDBFF) { Add some comments about this block is for UTF16 surrogate pairs. @@ +2839,5 @@ > + bool hasDash = false; > + > + do { > + if (name[i] >= 0xD800 && name[i] <= 0xDBFF) { > + char16_t high_surrogates = name[i]; Nit: camelCase for variable names and remove 's', e.g. highSurrogate. here and elsewhere. @@ +2840,5 @@ > + > + do { > + if (name[i] >= 0xD800 && name[i] <= 0xDBFF) { > + char16_t high_surrogates = name[i]; > + if ((i+1 < len) && name[i+1] >= 0xDC00 && name[i+1] <= 0xDFFF) { 1. Nit: Space around operators, here and elsewhere. 2. Bail out as early as possible. e.g. if ((i + 1) > len || name[i + 1] < 0xC00 || name[i + 1] > 0xDFFF) { return false; } @@ +2841,5 @@ > + do { > + if (name[i] >= 0xD800 && name[i] <= 0xDBFF) { > + char16_t high_surrogates = name[i]; > + if ((i+1 < len) && name[i+1] >= 0xDC00 && name[i+1] <= 0xDFFF) { > + char16_t low_surrogates = name[i+1]; Nit: s/low_surrogates/lowSurrogate/ @@ +2870,5 @@ > + (name[i] >= 0x2070 && name[i] <= 0x218F) || > + (name[i] >= 0x2C00 && name[i] <= 0x2FEF) || > + (name[i] >= 0x3001 && name[i] <= 0xD7FF) || > + (name[i] >= 0xF900 && name[i] <= 0xFDCF) || > + (name[i] >= 0xFDF0 && name[i] <= 0xFFFD)) { Use reverse logic and bail out early.
Attachment #8788848 - Flags: feedback?(echen)
(In reply to Edgar Chen [:edgar][:echen] from comment #5) > Comment on attachment 8788848 [details] [diff] [review] > Bug 1275832 - Implement custom element name validation for custom elements. > v1 > > Review of attachment 8788848 [details] [diff] [review]: > ----------------------------------------------------------------- > > Spec says name must not be any of the following: annotation-xml, Please ignore this, I missed removing it.
Addressed comment #2.
Attachment #8788848 - Attachment is obsolete: true
Attachment #8789317 - Flags: feedback?(echen)
Attachment #8789317 - Flags: feedback?(echen) → feedback+
Attachment #8789317 - Flags: review?(wchen)
Comment on attachment 8789317 [details] [diff] [review] Bug 1275832 - Implement custom element name validation for custom elements. v2 Review of attachment 8789317 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/base/nsContentUtils.cpp @@ +2849,5 @@ > + char16_t highSurrogate = name[i]; > + char16_t lowSurrogate = name[i+1]; > + // Merged two 16-bit surrogate pairs into code point. > + char32_t code = 0x10000 + ((highSurrogate - 0xD800) << 10) + > + (lowSurrogate - 0xDC00); There are some helper macros in nsCharTraits.h that will do the high/low surrogate check and combine into a code point.
Attachment #8789317 - Flags: review?(wchen) → review+
The previous patch hit testing/web-platform/meta/html/semantics/interfaces.html web-platform-test, and updated a new patch to address them. Try looks good: https://treeherder.mozilla.org/#/jobs?repo=try&revision=d5629778c1a775cb26a55cd38afabc1f1c58c5c3&filter-tier=1&selectedJob=27763482
Attachment #8792795 - Attachment is obsolete: true
Attachment #8793177 - Flags: review+
Keywords: checkin-needed
Blocks: 1275839
Pushed by ryanvm@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/b695086b9861 Implement custom element name validation for custom elements. r=wchen
Keywords: checkin-needed
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: