[Repo Assist] refactor: replace strings.SplitN(x, sep, 2) with strings.Cut#7628
Merged
lpcox merged 1 commit intoJun 16, 2026
Merged
Conversation
Three call-sites used strings.SplitN(x, sep, 2) followed by a len(parts) == 2 guard — the idiomatic Go 1.18+ equivalent is strings.Cut, which already appears in several other files in this codebase (server/session.go, proxy/proxy.go, tracing/). Changes: - internal/sanitize/sanitize.go (SanitizeArgs): replace strings.Contains+SplitN with strings.Cut; restructure to use continue so the else branch is eliminated - internal/envutil/envfile.go (LoadEnvFile): replace SplitN+len guard with strings.Cut+ok check; reassign key/value vars in place - internal/logger/logger.go (computeEnabled): replace SplitN+len guard with strings.Cut+ok for middle-wildcard pattern handling All three are semantically identical — strings.Cut splits at the first occurrence of the separator and returns (before, after, found), exactly matching SplitN(x, sep, 2) / len(parts)==2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors three existing string-splitting call sites to use strings.Cut instead of strings.SplitN(..., 2) + length checks, aligning these spots with the codebase’s existing idiomatic usage and avoiding intermediate slice allocations.
Changes:
- Updated
SanitizeArgsto usestrings.Cutfor parsingVAR=VALUEafter-e. - Updated
.envparsing inLoadEnvFileto usestrings.CutforKEY=VALUE. - Updated debug-pattern wildcard parsing in
matchPatternto usestrings.Cutfor middle-wildcard patterns.
Show a summary per file
| File | Description |
|---|---|
internal/sanitize/sanitize.go |
Refactors -e VAR=VALUE parsing to strings.Cut with early-continue. |
internal/envutil/envfile.go |
Refactors KEY=VALUE parsing to strings.Cut while preserving first-= semantics. |
internal/logger/logger.go |
Refactors middle-wildcard (prefix*suffix) parsing to strings.Cut. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 0
4 tasks
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.
🤖 This PR is from Repo Assist, an automated AI assistant for this repository.
Summary
Three call-sites across the codebase used the pattern:
The idiomatic Go 1.18+ equivalent is
strings.Cut, which already appears in 5+ other files in this codebase (server/session.go,proxy/proxy.go,tracing/). This PR applies it consistently in the remaining three locations.Changes
internal/sanitize/sanitize.goSanitizeArgsstrings.Contains+strings.SplitN+ index accessstrings.Cut+okcheck +continuepatterninternal/envutil/envfile.goLoadEnvFilestrings.SplitN(line, "=", 2)+len(parts) != 2strings.Cut(line, "=")+!okinternal/logger/logger.gocomputeEnabledstrings.SplitN(pattern, "*", 2)+len(parts) == 2strings.Cut(pattern, "*")+okAll three are semantically identical:
strings.Cut(s, sep)returns(before, after string, found bool), splitting on the first occurrence ofsep— exactly matching theSplitN(s, sep, 2)+len == 2guard pattern. Additionally,strings.Cutavoids an intermediate slice allocation.Rationale
strings.Cutwidely; these were the remaining outliersbefore, after, ok) are more expressive thanparts[0],parts[1],len(parts) == 2[]stringallocationNo behaviour changes. No new dependencies.
Test Status
Warning
Firewall blocked 6 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run