fix(opencode): skip env-var prefixes in shell permission pattern matching#29680
Open
JunJieLiu51520 wants to merge 1 commit into
Open
fix(opencode): skip env-var prefixes in shell permission pattern matching#29680JunJieLiu51520 wants to merge 1 commit into
JunJieLiu51520 wants to merge 1 commit into
Conversation
…hing The source() function returned the full node text including variable_assignment children (e.g. "GOFLAGS=-mod=vendor go test"). This caused permission rules like "go *": "allow" to never match commands with env-var prefixes. Now source() filters out variable_assignment children before constructing the pattern text, so "GOFLAGS=-mod=vendor go test ./..." correctly matches "go *". Closes anomalyco#14110
Contributor
|
The following comment was made by an LLM, it may be inaccurate: I found a potential duplicate: PR #28475: fix: strip inline env var prefixes from bash permission patterns This PR appears to be addressing the exact same issue - stripping environment variable prefixes from bash commands in permission pattern matching. Both PRs target the same problem where commands like |
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.
Issue for this PR
Closes #14110
Type of change
What does this PR do?
The
source()function in shell.ts returned the full tree-sitter node text includingvariable_assignmentchildren. This meant commands likeGOFLAGS=-mod=vendor go test ./...produced the pattern"GOFLAGS=-mod=vendor go test ./..."instead of"go test ./...", so permission rules like"go *": "allow"never matched.Now
source()filters outvariable_assignmentchild nodes before constructing the pattern text, so env-var prefixed commands correctly match their permission rules.How did you verify your code works?
Given a bash AST for
GOFLAGS=-mod=vendor go test ./..., tree-sitter parses it as acommandnode with children[variable_assignment("GOFLAGS=-mod=vendor"), word("go"), word("test"), word("./...")]. The fix skips thevariable_assignmentnode and joins the rest →"go test ./...", which matches"go *".Checklist