"TypeError: Cannot read property 'trim' of undefined" exception
Html-validate 5.0.1 throws a "TypeError: Cannot read property 'trim' of undefined" exception when the markup contains an element whose style
attribute ends with a space (including containing only one space).
Reduced test-case
<p style=" "></p>
This is in the following file, validated with html-validate source.html
.
The above is the whole HTML used, i.e. the whole content of the file. The same exception happens in a more proper HTML document too:
<!DOCTYPE html>
<html>
<body>
<p style=" "></p>
</body>
</html>
Note that the exception still happens if the p
tag is as follows (observe the space at the end of style
:
<p style="text-align: justify; "></p>
Configuration
No custom configuration, just run html-validate source.html
after a fresh npm install html-validate
. The configuration output is as follows:
Expected result
Actual validation errors, like the ones showing after the offending space is removed ("1:4 error Inline style is not allowed no-inline-style").
Actual result
I get the following output:
html-validate source.html
Validator crashed when parsing "source.html"
Caught exception:
TypeError: Cannot read property 'trim' of undefined
at C:\Users\MyUser\AppData\Roaming\npm\node_modules\html-validate\dist\cjs\core.js:4242:58
at Array.map (<anonymous>)
at getCSSDeclarations (C:\Users\MyUser\AppData\Roaming\npm\node_modules\html-validate\dist\cjs\core.js:4240:10)
at NoInlineStyle.allPropertiesAllowed (C:\Users\MyUser\AppData\Roaming\npm\node_modules\html-validate\dist\cjs\core.js:4333:30)
at C:\Users\MyUser\AppData\Roaming\npm\node_modules\html-validate\dist\cjs\core.js:4302:22
at C:\Users\MyUser\AppData\Roaming\npm\node_modules\html-validate\dist\cjs\core.js:1422:17
at C:\Users\MyUser\AppData\Roaming\npm\node_modules\html-validate\dist\cjs\core.js:7951:22
at Array.forEach (<anonymous>)
at EventHandler.trigger (C:\Users\MyUser\AppData\Roaming\npm\node_modules\html-validate\dist\cjs\core.js:7950:19)
at Parser.trigger (C:\Users\MyUser\AppData\Roaming\npm\node_modules\html-validate\dist\cjs\core.js:8430:20)
This is a bug in html-validate-5.0.1.
Please file a bug at https://gitlab.com/html-validate/html-validate/issues/new?issuable_template=Bug
and include this message in full and if possible the content of the
file being parsed (or a reduced testcase).
Version
-
html-validate
: 5.0.1 -
html-validate-angular
: not used -
html-validate-vue
: not used -
html-validate-protractor
: not used . any other relevant plugin: not used