Implement "relaxed" element/attribute name-validation rules, per: - https://github.com/whatwg/dom/pull/1079 - https://github.com/whatwg/html/pull/7991 - https://github.com/whatwg/html/pull/11453 That aligns DOM-API name behavior with HTML parser behavior - which has always allowed a wider range of characters in element and attribute names. New validation functions in nsContentUtils: - IsValidElementLocalName(): For createElement - allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - IsValidAttributeName(): For setAttribute/toggleAttribute/createAttribute - no null, whitespace, /, >, or = - IsValidNamespacePrefix(): For *NS methods - no null, whitespace, /, or > - IsValidDoctypeName(): For createDocumentType - no null, whitespace, or > - ParseQualifiedNameRelaxed(): Validates and parses qualified names with relaxed rules ParseQualifiedNameRelaxed() correctly implements the "strictly split" algorithm per the DOM spec: for qualified names with multiple colons like "f:o:o", the local name is just the second token ("o"), not everything after the first colon ("o:o"). This matches the spec's requirement to split on all colons and use only splitResult[0] as prefix and splitResult[1] as localName. Deleted outdated DOM Level 1 mochitest tests that tested old XML-based name validation rules; WPT name-validation.html provides coverage for the new relaxed rules. Removed WPT expected-failure .ini files, since all tests now pass. Differential Revision: https://phabricator.services.mozilla.com/D277822
99 lines
2.3 KiB
HTML
99 lines
2.3 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=658746
|
|
-->
|
|
<head>
|
|
<title>Test for Bug 658746</title>
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=658746">Mozilla Bug 658746</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script type="application/javascript">
|
|
|
|
/** Test for Bug 658746 */
|
|
|
|
/**
|
|
* Sets property, gets property and deletes property.
|
|
*/
|
|
function SetGetDelete(prop)
|
|
{
|
|
var el = document.createElement('div');
|
|
|
|
el.dataset[prop] = 'aaaaaa';
|
|
is(el.dataset[prop], 'aaaaaa', 'Dataset property "' + prop + '" should have been set.');
|
|
|
|
delete el.dataset[prop];
|
|
is(el.dataset[prop], undefined, 'Dataset property"' + prop + '" should have been deleted.');
|
|
}
|
|
|
|
/**
|
|
* Gets, deletes and sets property. Expects exception while trying to set property.
|
|
*/
|
|
function SetExpectException(prop)
|
|
{
|
|
var el = document.createElement('div');
|
|
|
|
is(el.dataset[prop], undefined, 'Dataset property "' + prop + '" should be undefined.');
|
|
delete el.dataset[prop];
|
|
|
|
try {
|
|
el.dataset[prop] = "xxxxxx";
|
|
ok(false, 'Exception should have been thrown when setting "' + prop + '".');
|
|
} catch (ex) {
|
|
ok(true, 'Exception should have been thrown.');
|
|
}
|
|
}
|
|
|
|
// Numbers as properties.
|
|
SetGetDelete(-12345678901234567000);
|
|
SetGetDelete(-1);
|
|
SetGetDelete(0);
|
|
SetGetDelete(1);
|
|
SetGetDelete(12345678901234567000);
|
|
|
|
// Floating point numbers as properties.
|
|
SetGetDelete(-1.1);
|
|
SetGetDelete(0.0);
|
|
SetGetDelete(1.1);
|
|
|
|
// Hexadecimal numbers as properties.
|
|
SetGetDelete(0x3);
|
|
SetGetDelete(0xa);
|
|
|
|
// Octal numbers as properties.
|
|
SetGetDelete(0o3);
|
|
SetGetDelete(0o7);
|
|
|
|
// String numbers as properties.
|
|
SetGetDelete('0');
|
|
SetGetDelete('01');
|
|
SetGetDelete('0x1');
|
|
|
|
// Undefined as property.
|
|
SetGetDelete(undefined);
|
|
|
|
// Empty arrays as properties.
|
|
SetGetDelete(new Array());
|
|
SetGetDelete([]);
|
|
|
|
// Non-empty array as property - comma is now valid with relaxed attribute rules.
|
|
SetGetDelete(['a', 'b']);
|
|
// Object as property - "[object Object]" contains space which is still invalid.
|
|
SetExpectException({'a':'b'});
|
|
|
|
// Objects as properties.
|
|
SetExpectException(new Object());
|
|
SetExpectException(document);
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|