From 75cf9d16cea85a4e31e9818219c05d3ed8cb5c93 Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Tue, 6 Dec 2016 23:11:30 +0100 Subject: [PATCH] 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 @@ +