You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/services/repository
Yarden Shoham 43d1183f67
escape filename when assemble URL (#22850) (#22871)
Backport #22850

Fixes: #22843 

### Cause:

affdd40296/services/repository/files/content.go (L161)

Previously, we did not escape the **"%"** that might be in "treePath"
when call "url.parse()".


![image](https://user-images.githubusercontent.com/33891828/218066318-5a909e50-2a17-46e6-b32f-684b2aa4b91f.png)

This function will check whether "%" is the beginning of an escape
character. Obviously, the "%" in the example (hello%mother.txt) is not
that. So, the function will return a error.

### Solution:
We can escape "treePath" by call "url.PathEscape()" function firstly.

### Screenshot:

![image](https://user-images.githubusercontent.com/33891828/218069781-1a030f8b-18d0-4804-b0f8-73997849ef43.png)

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: sillyguodong <33891828+sillyguodong@users.noreply.github.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
2 years ago
..
archiver Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
files escape filename when assemble URL (#22850) (#22871) 2 years ago
adopt.go Do not list active repositories as unadopted (#22034) (#22166) 2 years ago
adopt_test.go Fix repository adoption on Windows (#21646) (#21650) 2 years ago
avatar.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
avatar_test.go Refactor AssertExistsAndLoadBean to use generics (#20797) 3 years ago
branch.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
cache.go Slightly simplify LastCommitCache (#20444) 3 years ago
check.go Continue GCing other repos on error in one repo (#22422) (#22425) 2 years ago
fork.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
fork_test.go Move some files into models' sub packages (#20262) 3 years ago
hooks.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
main_test.go Use a struct as test options (#19393) 3 years ago
push.go When updating by rebase we need to set the environment for head repo (#22535) (#22536) 2 years ago
repository.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
repository_test.go Move some repository related code into sub package (#19711) 3 years ago
review.go Move some repository related code into sub package (#19711) 3 years ago
review_test.go Refactor AssertExistsAndLoadBean to use generics (#20797) 3 years ago
template.go Remove manual rollback for failed generated repositories (#20639) 3 years ago
transfer.go Move some files into models' sub packages (#20262) 3 years ago
transfer_test.go Move some files into models' sub packages (#20262) 3 years ago