shepmaster / sxd-xpath

An XPath library in Rust
Apache License 2.0
121 stars 34 forks source link

Core XPath functions that accept strings should implicitly convert arguments to a string #113

Closed hgrecco closed 7 years ago

hgrecco commented 7 years ago

First let me say that I by no means an expert on XPath. Therefore I do not really know what does the spec say. Having said that, I was trying to achieve something similar to what is showing here. The expression //*[text()[contains(.,'ABC')]] was working perfectly in xpath tester sites such as this but not with sxd-xpath. In order to make it work, I had to change it to: //*[text()[contains(string(),'ABC')]] Is this a bug or the the other libraries are too permisive?

shepmaster commented 7 years ago

Hmm, that's a very good question!

The spec has this to say for contains:

Function: boolean contains(string, string)

The contains function returns true if the first argument string contains the second argument string, and otherwise returns false.

The reason I chose the current behavior is because other functions, like string, explicitly say to convert the types.

That being said, libxml2 and Xalan C++ and Java all implicitly convert these to strings.

I think this library might be 10-15 years too late to try and forge a new path, so I'll probably need to bend to the majority will here... 😅