GetFile: Use "ref" in-query if posible #491

Merged
6543 merged 9 commits from 6543/go-sdk:GetFile_use-ref_in-query_if-posible into master 8 months ago
6543 commented 8 months ago
Collaborator
based on https://github.com/go-gitea/gitea/pull/14563
6543 added this to the v0.14.0 milestone 8 months ago
6543 added the
kind/enhancement
label 8 months ago
6543 added 1 commit 8 months ago
0b46b13343
GetFile: use ref in-query if posible
6543 added 1 commit 8 months ago
42dfc52e3d
GetFile: test with ref="" and ref not default branch
6543 added 1 commit 8 months ago
58f3add627
bytes.Equal
zeripath reviewed 8 months ago
Dismissed
if c.checkServerVersionGreaterThanOrEqual(version1_14_0) != nil {
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", owner, repo, ref, tree), nil, nil)
}
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s?ref=%s", owner, repo, tree, ref), nil, nil)
Poster
Collaborator

tree and ref should both be escaped properly.

ref is simple as it's url.QueryEscape but tree needs escaping using the partial pathescape.

tree and ref should both be escaped properly. ref is simple as it's url.QueryEscape but tree needs escaping using the partial pathescape.
6543 marked this conversation as resolved
6543 added 1 commit 8 months ago
c60731a1f2
QueryEscape
techknowlogick approved these changes 8 months ago
Dismissed
6543 added 1 commit 8 months ago
e1bfd1ce6f
extreme test branch naming
6543 added 1 commit 8 months ago
c2b7a504b9
test content itselve too
zeripath reviewed 8 months ago
Dismissed
if c.checkServerVersionGreaterThanOrEqual(version1_14_0) != nil {
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", owner, repo, ref, tree), nil, nil)
}
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s?ref=%s", owner, repo, tree, url.QueryEscape(ref)), nil, nil)
Poster
Collaborator

tree needs to be util.PathEscapeSegments or something like it.

e.g. from Gitea modules/util

// PathEscapeSegments escapes segments of a path while not escaping forward slash
func PathEscapeSegments(path string) string {
	slice := strings.Split(path, "/")
	for index := range slice {
		slice[index] = url.PathEscape(slice[index])
	}
	escapedPath := strings.Join(slice, "/")
	return escapedPath
}

as does ref and tree on line 123

tree needs to be `util.PathEscapeSegments` or something like it. e.g. from Gitea modules/util ``` // PathEscapeSegments escapes segments of a path while not escaping forward slash func PathEscapeSegments(path string) string { slice := strings.Split(path, "/") for index := range slice { slice[index] = url.PathEscape(slice[index]) } escapedPath := strings.Join(slice, "/") return escapedPath } ``` as does ref and tree on line 123
6543 commented 8 months ago
Poster
Collaborator

this is a more genneral issue witch I like to catch with #273 since we need this not only for this function...

this is a more genneral issue witch I like to catch with #273 since we need this not only for this function...
6543 marked this conversation as resolved
6543 added 1 commit 8 months ago
12c4dc167b
pathEscapeSegments
6543 added 2 commits 8 months ago
c19c73c06b
Test: use strange file name
zeripath approved these changes 8 months ago
Dismissed
6543 merged commit 32b0722f98 into master 8 months ago
6543 deleted branch GetFile_use-ref_in-query_if-posible 8 months ago
continuous-integration/drone/pr Build is passing
The pull request has been merged as 32b0722f98.
Sign in to join this conversation.
Loading…
There is no content yet.