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

[feature-request] Ignore validation for certain values

Open CatchABus opened this issue 3 years ago • 5 comments
trafficstars

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.

CatchABus avatar Jan 06 '22 16:01 CatchABus

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.

github-actions[bot] avatar Jan 06 '22 16:01 github-actions[bot]

I believe the only issue here is >, right?

amitguptagwl avatar Jan 07 '22 00:01 amitguptagwl

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.

CatchABus avatar Jan 07 '22 14:01 CatchABus

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 avatar Jan 08 '22 12:01 amitguptagwl

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:

amitguptagwl avatar Jan 08 '22 13:01 amitguptagwl