From fc977a2abecb2eef8fd87537ea8dc0ea28b51426 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 24 Dec 2016 13:18:57 -0500 Subject: [PATCH] provide useful feedback on encountering void element closing tag --- src/parse/state/tag.js | 4 ++++ test/parser/error-void-closing/error.json | 8 ++++++++ test/parser/error-void-closing/input.html | 1 + 3 files changed, 13 insertions(+) create mode 100644 test/parser/error-void-closing/error.json create mode 100644 test/parser/error-void-closing/input.html diff --git a/src/parse/state/tag.js b/src/parse/state/tag.js index c3fa1a122258..2db102ab0d7d 100644 --- a/src/parse/state/tag.js +++ b/src/parse/state/tag.js @@ -47,6 +47,10 @@ export default function tag ( parser ) { parser.allowWhitespace(); if ( isClosingTag ) { + if ( voidElementNames.test( name ) ) { + parser.error( `<${name}> is a void element and cannot have children, or a closing tag`, start ); + } + if ( !parser.eat( '>' ) ) parser.error( `Expected '>'` ); const element = parser.current(); diff --git a/test/parser/error-void-closing/error.json b/test/parser/error-void-closing/error.json new file mode 100644 index 000000000000..8756a518782f --- /dev/null +++ b/test/parser/error-void-closing/error.json @@ -0,0 +1,8 @@ +{ + "message": " is a void element and cannot have children, or a closing tag", + "loc": { + "line": 1, + "column": 23 + }, + "pos": 23 +} diff --git a/test/parser/error-void-closing/input.html b/test/parser/error-void-closing/input.html new file mode 100644 index 000000000000..886b019891a3 --- /dev/null +++ b/test/parser/error-void-closing/input.html @@ -0,0 +1 @@ +this is illegal!