From 7d0c8629c6b7afe82953e86b7351ae30be41730c Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Tue, 9 Jan 2018 19:00:44 +0100 Subject: [PATCH] feat(parser): only warn + skip on attribute overrides This is a follow up for: * 4b85697e99509cd733636dbaaa07c456f3ce941e * 75b6bb2ed754732de37f8a9a0921c84f256f3ca0 ...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. --- parser.js | 2 +- test/elements.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/parser.js b/parser.js index 09975bc..a2f216f 100644 --- a/parser.js +++ b/parser.js @@ -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; diff --git a/test/elements.js b/test/elements.js index dc189dd..b2cd5ac 100644 --- a/test/elements.js +++ b/test/elements.js @@ -980,7 +980,7 @@ test({ ns: true, expect: [ ['warn', 'attribute already defined'], - ['openTag', 'e:root', false], + ['openTag', 'e:root', { 'xmlns:e': 'http://extensions' } ], ['closeTag', 'e:root'] ], }); @@ -991,7 +991,7 @@ test({ ns: true, expect: [ ['warn', 'attribute already defined'], - ['openTag', 'ns0:root', false], + ['openTag', 'ns0:root', { xmlns: 'http://extensions' }], ['closeTag', 'ns0:root'] ], }); @@ -1001,7 +1001,7 @@ test({ xml: '', expect: [ ['warn', 'attribute already defined'], - ['openTag', 'root', false], + ['openTag', 'root', { a: 'A' }], ['closeTag', 'root'] ], }); @@ -1012,18 +1012,22 @@ test({ ns: true, expect: [ ['warn', 'attribute 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: '', + xml: '', ns: true, expect: [ ['warn', 'attribute already defined'], - ['openTag', 'ns0:root', false], + ['openTag', 'ns0:root', { + xmlns: 'http://extensions', + 'xmlns:bar': 'http://bar', + 'bar:a': 'A' + } ], ['closeTag', 'ns0:root'] ], });