fix(tool/code_search): guard option-like refs in buildGrepArgs - #737
Closed
aalhadxx wants to merge 1 commit into
Closed
fix(tool/code_search): guard option-like refs in buildGrepArgs#737aalhadxx wants to merge 1 commit into
aalhadxx wants to merge 1 commit into
Conversation
Moves the defense-in-depth check from gitGrep() into buildGrepArgs() so the guard is co-located with argument construction. Adds a comment explaining why --end-of-options can't be used here: git grep < 2.45 does not support --end-of-options before the revision. Adds TestBuildGrepArgs_RejectsOptionLikeRef. Signed-off-by: Aalhad <aalhadxx@users.noreply.github.com>
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
Collaborator
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.
Related: closes #645, follow-up to #663
Summary
As discussed in #663 (comment), this PR moves the defense-in-depth check for option-like refs into
buildGrepArgsinstead of keeping it ingitGrep. This keeps the guard co-located with argument construction (the same pattern the other tools follow) and adds a clear comment explaining whygit grepis the one invocation where we can't use--end-of-options.What changed
internal/tool/code_search.go:buildGrepArgsnow rejects refs starting with-and returnsnil.git grep < 2.45doesn't support--end-of-optionsbefore the revision.gitGreppropagates thenilfrombuildGrepArgsas the existing"Error: ref must not start with '-'" message.internal/tool/code_search_test.go:TestBuildGrepArgs_RejectsOptionLikeRefto assert the guard lives inbuildGrepArgs.TestGitGrep_RejectsOptionLikeRefandTestGitGrep_OptionLikeRefDoesNotLaunchPagerfor end-to-end coverage.Why this structure
The codebase already validates refs upstream in
validateReviewRefs, but thebuildGrepArgsguard ensures the defense-in-depth is visible right where arguments are built. If anyone ever callsbuildGrepArgsfrom a new path, the guard still holds.