Skip to content

XPath AST serialization does not account for operator precedence #44

Description

@altin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions