-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix joined urls #26774
Closed
Closed
Fix joined urls #26774
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e87576b
Fix joined url.
KN4CK3R e823e33
Fix MakeAbsoluteAssetURL.
KN4CK3R 607e4c7
Merge branch 'main' of https://github.com/go-gitea/gitea into fix-25632
KN4CK3R c43b04c
Merge branch 'main' of https://github.com/go-gitea/gitea into fix-25632
KN4CK3R File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,35 +13,148 @@ import ( | |
) | ||
|
||
func TestURLJoin(t *testing.T) { | ||
type test struct { | ||
Expected string | ||
cases := []struct { | ||
Base string | ||
Elements []string | ||
} | ||
newTest := func(expected, base string, elements ...string) test { | ||
return test{Expected: expected, Base: base, Elements: elements} | ||
Elems []string | ||
Expected string | ||
}{ | ||
{ | ||
Base: "https://try.gitea.io", | ||
Elems: []string{"a/b", "c"}, | ||
Expected: "https://try.gitea.io/a/b/c", | ||
}, | ||
{ | ||
Base: "https://try.gitea.io/", | ||
Elems: []string{"a/b", "c"}, | ||
Expected: "https://try.gitea.io/a/b/c", | ||
}, | ||
{ | ||
Base: "https://try.gitea.io/", | ||
Elems: []string{"/a/b/", "/c/"}, | ||
Expected: "https://try.gitea.io/a/b/c", | ||
}, | ||
{ | ||
Base: "https://try.gitea.io/", | ||
Elems: []string{"/a/./b/", "../c/"}, | ||
Expected: "https://try.gitea.io/a/c", | ||
}, | ||
{ | ||
Base: "a", | ||
Elems: []string{"b/c/"}, | ||
Expected: "a/b/c", | ||
}, | ||
{ | ||
Base: "a/", | ||
Elems: []string{"b/c/", "/../d/"}, | ||
Expected: "a/b/d", | ||
}, | ||
{ | ||
Base: "https://try.gitea.io", | ||
Elems: []string{"a/b", "c#d"}, | ||
Expected: "https://try.gitea.io/a/b/c#d", | ||
}, | ||
{ | ||
Base: "/a/", | ||
Elems: []string{"b/c/", "/../d/"}, | ||
Expected: "/a/b/d", | ||
}, | ||
{ | ||
Base: "/a", | ||
Elems: []string{"b/c/"}, | ||
Expected: "/a/b/c", | ||
}, | ||
{ | ||
Base: "/a", | ||
Elems: []string{"b/c#hash"}, | ||
Expected: "/a/b/c#hash", | ||
}, | ||
{ | ||
Base: "\x7f", // invalid url | ||
Expected: "", | ||
}, | ||
{ | ||
Base: "path", | ||
Expected: "path/", | ||
}, | ||
{ | ||
Base: "/path", | ||
Expected: "/path/", | ||
}, | ||
{ | ||
Base: "path/", | ||
Expected: "path/", | ||
}, | ||
{ | ||
Base: "/path/", | ||
Expected: "/path/", | ||
}, | ||
{ | ||
Base: "path", | ||
Elems: []string{"sub"}, | ||
Expected: "path/sub", | ||
}, | ||
{ | ||
Base: "/path", | ||
Elems: []string{"sub"}, | ||
Expected: "/path/sub", | ||
}, | ||
{ | ||
Base: "https://gitea.com", | ||
Expected: "https://gitea.com/", | ||
}, | ||
{ | ||
Base: "https://gitea.com/", | ||
Expected: "https://gitea.com/", | ||
}, | ||
{ | ||
Base: "https://gitea.com", | ||
Elems: []string{"sub/path"}, | ||
Expected: "https://gitea.com/sub/path", | ||
}, | ||
{ | ||
Base: "https://gitea.com/", | ||
Elems: []string{"sub", "path"}, | ||
Expected: "https://gitea.com/sub/path", | ||
}, | ||
{ | ||
Base: "https://gitea.com/", | ||
Elems: []string{"sub", "..", "path"}, | ||
Expected: "https://gitea.com/path", | ||
}, | ||
{ | ||
Base: "https://gitea.com/", | ||
Elems: []string{"sub/..", "path"}, | ||
Expected: "https://gitea.com/path", | ||
}, | ||
{ | ||
Base: "https://gitea.com/", | ||
Elems: []string{"sub", "../path"}, | ||
Expected: "https://gitea.com/path", | ||
}, | ||
{ | ||
Base: "https://gitea.com/", | ||
Elems: []string{"sub/../path"}, | ||
Expected: "https://gitea.com/path", | ||
}, | ||
{ | ||
Base: "https://gitea.com/", | ||
Elems: []string{"sub", ".", "path"}, | ||
Expected: "https://gitea.com/sub/path", | ||
}, | ||
{ | ||
Base: "https://gitea.com/", | ||
Elems: []string{"sub", "/", "path"}, | ||
Expected: "https://gitea.com/sub/path", | ||
}, | ||
{ // https://github.com/go-gitea/gitea/issues/25632 | ||
Base: "/owner/repo/media/branch/main", | ||
Elems: []string{"/../other/image.png"}, | ||
Expected: "/owner/repo/media/branch/other/image.png", | ||
}, | ||
Comment on lines
+149
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Old code: |
||
} | ||
for _, test := range []test{ | ||
newTest("https://try.gitea.io/a/b/c", | ||
"https://try.gitea.io", "a/b", "c"), | ||
newTest("https://try.gitea.io/a/b/c", | ||
"https://try.gitea.io/", "/a/b/", "/c/"), | ||
newTest("https://try.gitea.io/a/c", | ||
"https://try.gitea.io/", "/a/./b/", "../c/"), | ||
newTest("a/b/c", | ||
"a", "b/c/"), | ||
newTest("a/b/d", | ||
"a/", "b/c/", "/../d/"), | ||
newTest("https://try.gitea.io/a/b/c#d", | ||
"https://try.gitea.io", "a/b", "c#d"), | ||
newTest("/a/b/d", | ||
"/a/", "b/c/", "/../d/"), | ||
newTest("/a/b/c", | ||
"/a", "b/c/"), | ||
newTest("/a/b/c#hash", | ||
"/a", "b/c#hash"), | ||
Comment on lines
-25
to
-42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Converted these test cases into a (for me) more readable format. |
||
} { | ||
assert.Equal(t, test.Expected, URLJoin(test.Base, test.Elements...)) | ||
|
||
for i, c := range cases { | ||
assert.Equal(t, c.Expected, URLJoin(c.Base, c.Elems...), "Unexpected result in test case %v", i) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
banch name can also have # like
BranchName#123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct but does not affect the method because it is called with already escaped parameters.
The screenshot shows a branch with
#
with a readme which includes the picture from the repo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, works for me then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some test cases are failing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why this PR is marked as depending on the other PR. If #26745 is merged, the test will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohk, got it. my bad.