BaseXdb / basex

BaseX Main Repository.
http://basex.org
BSD 3-Clause "New" or "Revised" License
684 stars 265 forks source link

XQuery: Bug of operation on non-existing attribute #2190

Closed Twilight-Shuxin closed 1 year ago

Twilight-Shuxin commented 1 year ago

Description of the Problem

Given this XML document:

<T1 id="1">1</T1>

and XPath Query

//T1[(@t1 <= 0) or (@t1 >= -10)]

BaseX give result

<T1 id="1">1</T1>

Expected Behavior

Should return empty result set as Saxon & Exist db.

Steps to Reproduce the Behavior

  1. Create database create database test
  2. Insert XML file into database put test.xml path/to/file
  3. Execute XPath query xquery //T1[(@t1 <= 0) or (@t1 >= -10)]

Do you have an idea how to solve the issue?

No response

What is your configuration?

BaseX version: 10.5 latest stable snapshot on Windows

ChristianGruen commented 1 year ago

Good catch. The comparisons were rewritten to true(), no matter if @t1 returned a result. It’s now rewritten as follows:

//T1[@t1 <= 0 or @t1 >= -10]
→ //T1[exists(@t1)]
→ //T1[@t1]

Please note that <x/>[. <= 0 or . >= 0] will not raise an error, even though the input cannot be converted to a double value. Both results are correct: The language specification allows code to be simplified if valid input would always yield the same result.

Another example is <x/>[exists(xs:double(.))], which gives different results depending on the query processor you use.

Twilight-Shuxin commented 1 year ago

Thanks a lot!