Validation of invalid XML declarations
bendrissou opened this issue · comments
Description
The parser accepts incorrect XML declarations as valid, without raising an error. This is despite enabling the validator option "-v".
Input
<?xml version="1.0" var ?> <a/>
There is an unassigned attribute var
, which I expected to raise an error. The input is saved in a file named example.xml
.
Code
./src/cli/cli.js -v example.xml
Output
{ '?xml': { '@_version': 1 }, a: '' }
My question is: Why the XML validator doesn't throw an error?
Please note that xmllint rejects the input example as invalid.
Can you please confirm if this is a valid issue?
Sorry I missed your original message. FXP validator checks for syntax error only, any other issue like scheme related, or the one you're highlighted are not covered.
I'm not sure about this issue but you can check it by disallowing boolean attributes. I guess it is by default is set to allow.
I believe this is a syntax error. The expression does not conform to the XML syntax, or the XML grammar. So I assume this is unintended behaviour?
Have you checked by disallowing boolean attributes?
As shown above, I have enabled the -v
option.
I assume the -v
flag should force the validation of the input before parsing. Is that correct?
Please try it from the code. I'm not sure if the CLI is updated with all the options. This docs can help you.
const {XMLValidator} = require("fast-xml-parser");
const result = XMLValidator.validate(xmlData, {
allowBooleanAttributes: true
});
I have tried the code above:
#!/usr/bin/env node
const {XMLValidator} = require("../fxp");
const result = XMLValidator.validate('<?xml version="1.0" var ?> <a/>', {
allowBooleanAttributes: true
});
console.log(result);
Output is:
true
The XML input was accepted, despite having the unassigned attribute var
.
As I remember, The validator has no check for xml description tag. same with v5