Serializing an XPath AST does not wrap expressions with higher precedence in parentheses, changing the meaning of the resultant XPath.
Example:
from eulxml import xpath
ast = xpath.parse('cond1 and (cond2 or cond3 or cond4)')
# >>> <BinaryExpression cond1 and cond2 or cond3 or cond4>
print(xpath.ast.serialize(ast))
# >>> cond1 and cond2 or cond3 or cond4
# CORRECT >>> cond1 and (cond2 or cond3 or cond4)
cond1 and cond2 or cond3 or cond4 and cond1 and (cond2 or cond3 or cond4) are not equivalent.
It looks like this bug is in the serialization logic (ast.py) and not in the parsing logic, as the AST appears to have the correct hierarchy when indicating precedence using parentheses.
Serializing an XPath AST does not wrap expressions with higher precedence in parentheses, changing the meaning of the resultant XPath.
Example:
cond1 and cond2 or cond3 or cond4
andcond1 and (cond2 or cond3 or cond4)
are not equivalent.It looks like this bug is in the serialization logic (
ast.py
) and not in the parsing logic, as the AST appears to have the correct hierarchy when indicating precedence using parentheses.