From bc54600b6d6fb3d577030e1ff5e1531f9aa3a862 Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Tue, 6 Dec 2016 23:11:30 +0100 Subject: [PATCH 1/2] Make sure parser only allows unique attribute names --- compiler/parse/state/tag.js | 11 +++++++++-- test/parser/attribute-unique-error/error.json | 8 ++++++++ test/parser/attribute-unique-error/input.html | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/parser/attribute-unique-error/error.json create mode 100644 test/parser/attribute-unique-error/input.html diff --git a/compiler/parse/state/tag.js b/compiler/parse/state/tag.js index e8c627c93a..b949a033a0 100644 --- a/compiler/parse/state/tag.js +++ b/compiler/parse/state/tag.js @@ -74,9 +74,10 @@ export default function tag ( parser ) { } const attributes = []; + const uniqueNames = new Map(); let attribute; - while ( attribute = readAttribute( parser ) ) { + while ( attribute = readAttribute( parser, uniqueNames ) ) { attributes.push( attribute ); parser.allowWhitespace(); } @@ -133,11 +134,17 @@ function readTagName ( parser ) { return name; } -function readAttribute ( parser ) { +function readAttribute ( parser, uniqueNames ) { const start = parser.index; const name = parser.readUntil( /(\s|=|\/|>)/ ); if ( !name ) return null; + if ( uniqueNames.has(name) ) { + parser.error( 'Attributes need to be unique', start ); + return null; + } + + uniqueNames.set(name, true); parser.allowWhitespace(); diff --git a/test/parser/attribute-unique-error/error.json b/test/parser/attribute-unique-error/error.json new file mode 100644 index 0000000000..b4ab7a57b5 --- /dev/null +++ b/test/parser/attribute-unique-error/error.json @@ -0,0 +1,8 @@ +{ + "message": "Attributes need to be unique", + "loc": { + "line": 1, + "column": 17 + }, + "pos": 17 +} diff --git a/test/parser/attribute-unique-error/input.html b/test/parser/attribute-unique-error/input.html new file mode 100644 index 0000000000..4088350ce0 --- /dev/null +++ b/test/parser/attribute-unique-error/input.html @@ -0,0 +1 @@ +
From 923d56216440531f89d89aec17816882b01c562b Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Wed, 7 Dec 2016 00:11:48 +0100 Subject: [PATCH 2/2] Remove superfluous return. --- compiler/parse/state/tag.js | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/parse/state/tag.js b/compiler/parse/state/tag.js index b949a033a0..d8ac4fd776 100644 --- a/compiler/parse/state/tag.js +++ b/compiler/parse/state/tag.js @@ -141,7 +141,6 @@ function readAttribute ( parser, uniqueNames ) { if ( !name ) return null; if ( uniqueNames.has(name) ) { parser.error( 'Attributes need to be unique', start ); - return null; } uniqueNames.set(name, true);