xpath icon indicating copy to clipboard operation
xpath copied to clipboard

introduce CompileOptions, StrictEOF option

Open kovacsur opened this issue 6 months ago • 2 comments

The current implementation is a bit too forgiving for our use case. The particular issue that brought this to light was that an XPath expression like

//foo,garbage

will be parsed without issues. I propose the changes in this PR so that such expressions can be optionally rejected, while maintaining backward compatibility.

New versions of public functions are introduced that take the newly introduced CompileOptions parameter, with a single available option for now (the one that we needed for the case above).

There is another PR in the xmlquery repo to go with this one.

kovacsur avatar May 29 '25 20:05 kovacsur

Hello, thank you for this feedback.

The expression like //foo,garbage should be invalid, I hadn't considered this case before. I think we should return an error instead of maintaining compatibility. This way keeps the code simple and usable; Additionally, no code change or add are needed for the 'xmlquery' project.

zhengchun avatar May 30 '25 17:05 zhengchun

Sure, that works, too, assuming no one depends on the current behaviour (which they really shouldn't). Working in a corporate environment has made me extremely cautious about breaking backward compatibility, so adding an easily extensible flag system seemed like the right way to go. For our specific use case, simply throwing an error for expressions like this is sufficient.

kovacsur avatar May 31 '25 22:05 kovacsur