Skip to content

fix: fix index validation for PUT requests#6824

Merged
mholt merged 1 commit intocaddyserver:masterfrom
debug-ing:fix/caddy-api-put-6822
Feb 4, 2025
Merged

fix: fix index validation for PUT requests#6824
mholt merged 1 commit intocaddyserver:masterfrom
debug-ing:fix/caddy-api-put-6822

Conversation

@debug-ing
Copy link
Contributor

fix issues #6822

@CLAassistant
Copy link

CLAassistant commented Feb 3, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks. Did you double-check that the PUT logic below is still correct if idx == len(arr)?

case http.MethodPut:
    // avoid creation of new slice and a second copy (see
    // https://github.com/golang/go/wiki/SliceTricks#insert)
    arr = append(arr, nil)
    copy(arr[idx+1:], arr[idx:])
    arr[idx] = val
    v[part] = arr

@debug-ing
Copy link
Contributor Author

Yes, the PUT logic works correctly when idx == len(arr). It behaves as expected by appending the new element at the end of the array.

@debug-ing
Copy link
Contributor Author

debug-ing commented Feb 4, 2025

Hi, the code is all good—every test is passing except this one CI run. It hit a network issue where the self-hosted runner couldn't reach GitHub’s endpoints during the artifact upload.

@mholt
Copy link
Member

mholt commented Feb 4, 2025

Yeah, we have some known flaky tests. Thanks!

@mholt mholt merged commit 96c5c55 into caddyserver:master Feb 4, 2025
32 checks passed
mohammed90 pushed a commit to cedricziel/caddy that referenced this pull request Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caddy API PUT array insertion doesn't allow inserting at the end of the array

3 participants