Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation of invalid XML declarations #616

Open
bendrissou opened this issue Oct 3, 2023 · 8 comments
Open

Validation of invalid XML declarations #616

bendrissou opened this issue Oct 3, 2023 · 8 comments
Labels

Comments

@bendrissou
Copy link

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
Copy link
Author

Hi @amitguptagwl

Can you please confirm if this is a valid issue?

@amitguptagwl
Copy link
Member

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.

@bendrissou
Copy link
Author

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?

@amitguptagwl
Copy link
Member

Have you checked by disallowing boolean attributes?

@bendrissou
Copy link
Author

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?

@amitguptagwl
Copy link
Member

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

@bendrissou
Copy link
Author

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.

@amitguptagwl
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants