Skip to content

Fix ne operator incorrectly mutating ctx.Success via regex side-effect#93

Merged
oalders merged 2 commits into
mainfrom
fix/ne-operator-logic
Apr 23, 2026
Merged

Fix ne operator incorrectly mutating ctx.Success via regex side-effect#93
oalders merged 2 commits into
mainfrom
fix/ne-operator-logic

Conversation

@oalders

@oalders oalders commented Apr 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Removes erroneous ctx.Success = matched mutation from the Ne case in compare/compare.go
  • Removes dead code: operator == ops.Unlike branch inside Ne that could never be reached
  • The correct return got != want, nil was already there and is now the only statement in the case

Security / Correctness

Fixes Important finding #3 from security review: ne comparisons were setting ctx.Success based on a regex match result rather than string inequality, producing incorrect exit codes in scripts using is var X ne Y or similar.

Test plan

  • Regression tests: "foo" ne "bar" → success, "foo" ne "foo" → failure
  • go build ./... passes
  • go test ./... passes

🤖 Generated with Claude Code

… in Strings

The Ne case in compare.Strings was incorrectly setting ctx.Success based
on a regex match result, corrupting exit codes for ne comparisons. It also
contained dead code (operator == ops.Unlike branch) that could never be
reached since Unlike has its own case arm. The return value got != want is
the correct semantic; callers handle ctx.Success assignment.

Adds regression tests confirming ne returns false when values are equal
and true when they differ.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.83%. Comparing base (820dfc7) to head (528dc12).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   76.55%   76.83%   +0.28%     
==========================================
  Files          22       22              
  Lines        1382     1373       -9     
==========================================
- Hits         1058     1055       -3     
+ Misses        277      273       -4     
+ Partials       47       45       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oalders oalders merged commit 8e69595 into main Apr 23, 2026
3 checks passed
@oalders oalders deleted the fix/ne-operator-logic branch April 23, 2026 02:07
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