NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.54k stars 306 forks source link

[feature-request] Ignore validation for certain values #415

Open CatchABus opened 2 years ago

CatchABus commented 2 years ago

Description

It would be great if validator skipped certain expressions.

A case I noticed this could be useful is a framework that allows using javascript expressions as attribute values in XML. The format is usually like this:

<tagName value="5" text="{{ isVisible && isEditable }}"/>
<tagName value="5" text="{{ array.length > 5 }}"/>

As you can see, there is the case of using XML special characters for different functionality. I wonder if validator could be instructed to skip validation of attribute values using a regular expression.

github-actions[bot] commented 2 years ago

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

amitguptagwl commented 2 years ago

I believe the only issue here is >, right?

CatchABus commented 2 years ago

I believe the only issue here is >, right?

Thank you very much for your fast reply! It seems that none of them is the issue, though I wonder if validator should complain about both. Ampersand is also a special symbol and perhaps validator should not allow ampersand after ampersand. Regarding both cases, I didn't notice but I had also included quotes inside quotes in my own code and validator failed so I assumed it was special characters.

Validator can validate both cases.

amitguptagwl commented 2 years ago

Validator is not giving error for both of the examples currently. So, yes, it is a bug. And I believe it's quite easy to fix.

amitguptagwl commented 2 years ago

I'm leaving the bug open for sometimes, if someone want to try to fix it. Changes are required in validator.js:322. I believe current regular expression can't be fixed. So the function tagExpWithClosingIndex() from OrderedObjParser.js can be referred.

I'm even wondering if the validator code slowly can be merged to parser. :thinking: