Skip to content

Fix asymmetric none equality bug in Value::operator==#26

Open
ender672 wants to merge 1 commit intoochafik:mainfrom
ender672:fix-none-equality-operator
Open

Fix asymmetric none equality bug in Value::operator==#26
ender672 wants to merge 1 commit intoochafik:mainfrom
ender672:fix-none-equality-operator

Conversation

@ender672
Copy link
Copy Markdown

@ender672 ender672 commented Mar 3, 2026

Summary

none == [] and none == {} incorrectly return true, while [] == none and {} == none correctly return false.

When none is on the left side, operator== falls through to comparing primitive_ fields. Since arrays and objects leave primitive_ as the default json(null), it matches none's primitive and returns true.

Found while fuzzing minja and comparing to an experimental JS port.

Fix

Add an early return in the else branch of operator== when the other side has array_ or object_ set (1-line change in minja.hpp).

Test plan

  • Added NoneEquality test case in test-syntax.cpp covering both directions of none-vs-container comparisons
  • All existing tests continue to pass

When none is on the left side of `==`, the operator falls through to
comparing `primitive_` fields. Since arrays and objects leave `primitive_`
as the default `json(null)`, `none == []` and `none == {}` incorrectly
returned true while `[] == none` correctly returned false.

Add an early return when the other side has `array_` or `object_` set,
and add tests covering both directions of none-vs-container comparisons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant