Commit f20141c1 authored by deepak.sa@samsung.com's avatar deepak.sa@samsung.com

Invalid chars should not be allowed as first character in custom element name

This patch *disallows* usage of remaining combining chars as first
character in custom element name. Also, usage of colon (":") is not
allowed in custom element name. This restriction is according to the
NCName production mentioned in the specs.

BUG=325673
TEST=fast/dom/custom/invalid-first-char-combinators.html

Review URL: https://codereview.chromium.org/493713002

git-svn-id: svn://svn.chromium.org/blink/trunk@184957 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent beb0cadb
...@@ -17,7 +17,10 @@ test(function () { ...@@ -17,7 +17,10 @@ test(function () {
// Reserved names: // Reserved names:
// hyphen-containing names from the applicable specifications, // hyphen-containing names from the applicable specifications,
// namely the SVG and the MathML. // namely the SVG and the MathML.
'annotation-xml' 'annotation-xml',
// names containing colon
':-xfoo',
'xfoo-:yfoo'
]; ];
for (var i = 0; i < invalidNames.length; i++) { for (var i = 0; i < invalidNames.length; i++) {
......
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
test(function () {
var invalidCombinators = [ 0x0B83, 0x0F88, 0x0F89, 0x0F8A, 0x0F8B ];
for (var i = 0; i < invalidCombinators.length; i++) {
var invalidCombinator = String.fromCharCode(invalidCombinators[i]) + '-xfoo';
assert_throws('SYNTAX_ERR', function () {
document.registerElement(invalidCombinator);
}, 'registering custom element: *' +
invalidCombinator + '* should throw syntax error');
}
}, 'registering invalid first letter combinators, not covered in Document::validNames');
</script>
...@@ -66,6 +66,24 @@ void CustomElement::addEmbedderCustomElementName(const AtomicString& name) ...@@ -66,6 +66,24 @@ void CustomElement::addEmbedderCustomElementName(const AtomicString& name)
embedderCustomElementNames().append(lower); embedderCustomElementNames().append(lower);
} }
static inline bool isValidNCName(const AtomicString& name)
{
if (kNotFound != name.find(':'))
return false;
if (!name.string().is8Bit()) {
const UChar32 c = name.characters16()[0];
// These characters comes under CombiningChar in NCName and according to
// NCName only BaseChar and Ideodgraphic can come as first chars.
// Also these characters come under Letter_Other in UnicodeData, thats
// why they pass as valid document name.
if (c == 0x0B83 || c == 0x0F88 || c == 0x0F89 || c == 0x0F8A || c == 0x0F8B)
return false;
}
return Document::isValidName(name.string());
}
bool CustomElement::isValidName(const AtomicString& name, NameSet validNames) bool CustomElement::isValidName(const AtomicString& name, NameSet validNames)
{ {
if ((validNames & EmbedderNames) && kNotFound != embedderCustomElementNames().find(name)) if ((validNames & EmbedderNames) && kNotFound != embedderCustomElementNames().find(name))
...@@ -79,7 +97,7 @@ bool CustomElement::isValidName(const AtomicString& name, NameSet validNames) ...@@ -79,7 +97,7 @@ bool CustomElement::isValidName(const AtomicString& name, NameSet validNames)
} }
if (kNotFound == reservedNames.find(name)) if (kNotFound == reservedNames.find(name))
return Document::isValidName(name.string()); return isValidNCName(name);
} }
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment