Skip to content

Apply boolean coercion to equality comparisons - #157

Merged
zhengchun merged 1 commit into
antchfx:masterfrom
ac1982:fix/boolean-equality
Oct 14, 2026
Merged

zhengchun merged 1 commit into
antchfx:masterfrom
ac1982:fix/boolean-equality

Conversation

@ac1982

@ac1982 ac1982 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Equality currently converts booleans to numbers: 2 = true() returns false, '' = false() returns false, and a nonempty node-set can compare unequal to true depending on its text.

XPath 1.0 section 3.4 requires boolean conversion for equality/inequality when either operand is boolean, including node-set operands. Route those comparisons through asBool, treating NaN as false. Other comparison dispatch remains unchanged.

Adds 36 public expression cases covering both operand orders, numbers (including NaN), strings, and empty/nonempty node-sets; 20 fail before the fix. Corrects 14 existing equality expectations in TestBooleanComparison; all expressions in that table were independently checked against lxml/libxml2 using the same XML fixture. This complements #151's operand-order fix for relational comparisons.

Validation: go test -race -covermode=atomic -coverprofile=/tmp/xpath-bool.cover ./... (85.0% coverage), go vet ./..., and Go 1.14.15 go test ./... pass. git diff --check passes.

AI-assisted implementation and validation.

@zhengchun
zhengchun merged commit 2c1abb5 into antchfx:master Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants