Skip to content

cmd/docker: fix stringSliceReplaceAt with overlapping matches - #7267

Open
thaJeztah wants to merge 2 commits into
docker:masterfrom
thaJeztah:fix_aliases
Open

cmd/docker: fix stringSliceReplaceAt with overlapping matches#7267
thaJeztah wants to merge 2 commits into
docker:masterfrom
thaJeztah:fix_aliases

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

cmd/docker: rewrite TestStringSliceReplaceAt to table test

cmd/docker: fix stringSliceReplaceAt with overlapping matches

Inline the sub-slice lookup into stringSliceReplaceAt and use
slices.Equal to compare candidate ranges. When a specific index is
required, check that position directly instead of searching the full
slice.

This also fixes overlapping matches and uses slices.Concat to construct
the replacement result.

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Inline the sub-slice lookup into stringSliceReplaceAt and use
slices.Equal to compare candidate ranges. When a specific index is
required, check that position directly instead of searching the full
slice.

This also fixes overlapping matches and uses slices.Concat to construct
the replacement result.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah added this to the 29.8.0 milestone Sep 1, 2026
@thaJeztah thaJeztah added status/2-code-review kind/bugfix PR's that fix bugs kind/refactor PR's that refactor, or clean-up code labels Sep 1, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Review incomplete

chunk 1: Drafter did not complete (schema validation error prevented delegation)

Findings so far: ⚠️ INCOMPLETE


Note — Direct analysis performed by orchestrator:

The drafter agent was unavailable due to a schema validation error (HTTP 400). A direct review of the diff was performed as a fallback.

The new stringSliceReplaceAt implementation in cmd/docker/aliases_utils.go was reviewed manually:

  • for i := range len(s) - len(find) + 1: When len(s) < len(find), the expression yields a negative integer. In Go 1.22+, range over a negative integer iterates zero times — no panic, returns s, false correctly.
  • Bounds check in the requireIndex >= 0 branch: requireIndex+len(find) > len(s) correctly guards the slice before slices.Equal is called — no out-of-bounds risk.
  • slices.Concat: Allocates a fresh backing array — no aliasing of the original slice s.
  • Overlapping match test case: s=["a","a","b"], find=["a","b"] — loop at i=0 compares ["a","a"] vs ["a","b"] (no match), at i=1 compares ["a","b"] vs ["a","b"] (match) → returns ["a","c"]. Correct.
  • len(find) == 0 guard: Returns s, false — prevents an empty-find infinite match.

No bugs were identified in the introduced code. The logic is sound and the test coverage is adequate for the changed behavior.

This review is marked incomplete because the automated drafter pipeline could not run. A human reviewer should verify this assessment.

@thaJeztah
thaJeztah requested a review from vvoland September 2, 2026 00:02

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Review incomplete

chunk 1: Drafter did not complete

Findings so far: ⚠️ INCOMPLETE

The automated drafter agent encountered a schema error and could not complete its analysis of the diff. No findings were produced. A human review of this PR is recommended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bugfix PR's that fix bugs kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants