Skip to content

Commit

Permalink
feat(parser): only warn + skip on attribute overrides
Browse files Browse the repository at this point in the history
This is a follow up for:

* 4b85697
* 75b6bb2

...trying to come up with a reasonable, less backwards-
compatibilty breaking behavior.

We'll now simply warn on attribute overrides and
_continue_ to parse and NS-adjust valid attributes.

This is as close as we can get to the pre 5.6.x behavior.
  • Loading branch information
nikku committed Jan 9, 2018
1 parent c0335fc commit 7d0c862
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion parser.js
Expand Up @@ -389,7 +389,7 @@ function Saxen(options) {
// check attribute re-declaration
if (name in seenAttrs) {
handleWarning('attribute <' + name + '> already defined');
return cachedAttrs = false;
continue;
}

seenAttrs[name] = true;
Expand Down
16 changes: 10 additions & 6 deletions test/elements.js
Expand Up @@ -980,7 +980,7 @@ test({
ns: true,
expect: [
['warn', 'attribute <xmlns:e> already defined'],
['openTag', 'e:root', false],
['openTag', 'e:root', { 'xmlns:e': 'http://extensions' } ],
['closeTag', 'e:root']
],
});
Expand All @@ -991,7 +991,7 @@ test({
ns: true,
expect: [
['warn', 'attribute <xmlns> already defined'],
['openTag', 'ns0:root', false],
['openTag', 'ns0:root', { xmlns: 'http://extensions' }],
['closeTag', 'ns0:root']
],
});
Expand All @@ -1001,7 +1001,7 @@ test({
xml: '<root a="A" a="B" />',
expect: [
['warn', 'attribute <a> already defined'],
['openTag', 'root', false],
['openTag', 'root', { a: 'A' }],
['closeTag', 'root']
],
});
Expand All @@ -1012,18 +1012,22 @@ test({
ns: true,
expect: [
['warn', 'attribute <a> already defined'],
['openTag', 'ns0:root', false],
['openTag', 'ns0:root', { xmlns: 'http://extensions', a: 'A' }],
['closeTag', 'ns0:root']
],
});

// local attribute re-declaration / with other namespace
test({
xml: '<root xmlns="http://extensions" xmlns:bar="http://extensions" bar:a="A" bar:a="B" />',
xml: '<root xmlns="http://extensions" xmlns:bar="http://bar" bar:a="A" bar:a="B" />',
ns: true,
expect: [
['warn', 'attribute <bar:a> already defined'],
['openTag', 'ns0:root', false],
['openTag', 'ns0:root', {
xmlns: 'http://extensions',
'xmlns:bar': 'http://bar',
'bar:a': 'A'
} ],
['closeTag', 'ns0:root']
],
});

0 comments on commit 7d0c862

Please sign in to comment.