fast-xml-parser icon indicating copy to clipboard operation
fast-xml-parser copied to clipboard

Validation of invalid XML declarations

Open bendrissou opened this issue 2 years ago • 8 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.

bendrissou avatar Oct 03 '23 08:10 bendrissou

Hi @amitguptagwl

Can you please confirm if this is a valid issue?

bendrissou avatar Feb 06 '24 11:02 bendrissou

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.

amitguptagwl avatar Feb 08 '24 05:02 amitguptagwl

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?

bendrissou avatar Feb 08 '24 08:02 bendrissou

Have you checked by disallowing boolean attributes?

amitguptagwl avatar Feb 12 '24 05:02 amitguptagwl

Hi @amitguptagwl

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?

bendrissou avatar Feb 12 '24 13:02 bendrissou

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
});

amitguptagwl avatar Feb 13 '24 03:02 amitguptagwl

Hi @amitguptagwl

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.

bendrissou avatar Jun 10 '24 13:06 bendrissou

As I remember, The validator has no check for xml description tag. same with v5

amitguptagwl avatar Jun 12 '24 00:06 amitguptagwl