Skip to content

improve URL joining to prevent malformed cache service URLs #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025

Conversation

crazy-max
Copy link
Collaborator

@crazy-max crazy-max commented Jun 11, 2025

@@ -545,7 +545,7 @@ func (c *Cache) doWithRetries(ctx context.Context, r *request) (*http.Response,
}

func (c *Cache) url(p string) string {
return c.URL + "_apis/artifactcache/" + p
return strings.TrimRight(c.URL, "/") + "/_apis/artifactcache/" + p
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to sanitize / normalize the URL field as part of the constructor, or are there other ways the field can be / is expected to be set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking of parsing the URL with url.Parse and then u.Path, _ = url.JoinPath(u.Path, p) to finally return u.String() but opt for simple fix for this patch.

@crazy-max crazy-max merged commit 388a2ec into tonistiigi:master Jun 11, 2025
3 checks passed
@crazy-max crazy-max deleted the url-concat branch June 11, 2025 15:52
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.

3 participants