Make sure parser only allows unique attribute names

pull/135/head
Fabrice Weinberg 8 years ago
parent 657830354a
commit 75cf9d16ce

@ -74,9 +74,10 @@ export default function tag ( parser ) {
} }
const attributes = []; const attributes = [];
const uniqueNames = new Map();
let attribute; let attribute;
while ( attribute = readAttribute( parser ) ) { while ( attribute = readAttribute( parser, uniqueNames ) ) {
attributes.push( attribute ); attributes.push( attribute );
parser.allowWhitespace(); parser.allowWhitespace();
} }
@ -133,11 +134,17 @@ function readTagName ( parser ) {
return name; return name;
} }
function readAttribute ( parser ) { function readAttribute ( parser, uniqueNames ) {
const start = parser.index; const start = parser.index;
const name = parser.readUntil( /(\s|=|\/|>)/ ); const name = parser.readUntil( /(\s|=|\/|>)/ );
if ( !name ) return null; if ( !name ) return null;
if ( uniqueNames.has(name) ) {
parser.error( 'Attributes need to be unique', start );
return null;
}
uniqueNames.set(name, true);
parser.allowWhitespace(); parser.allowWhitespace();

@ -0,0 +1,8 @@
{
"message": "Attributes need to be unique",
"loc": {
"line": 1,
"column": 17
},
"pos": 17
}

@ -0,0 +1 @@
<div class='foo' class='bar'></div>
Loading…
Cancel
Save