Fix ne operator incorrectly mutating ctx.Success via regex side-effect#93
Merged
Conversation
… 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ctx.Success = matchedmutation from theNecase incompare/compare.gooperator == ops.Unlikebranch insideNethat could never be reachedreturn got != want, nilwas already there and is now the only statement in the caseSecurity / Correctness
Fixes Important finding #3 from security review:
necomparisons were settingctx.Successbased on a regex match result rather than string inequality, producing incorrect exit codes in scripts usingis var X ne Yor similar.Test plan
"foo" ne "bar"→ success,"foo" ne "foo"→ failurego build ./...passesgo test ./...passes🤖 Generated with Claude Code