Skip to content

Fixed 404 caused by unexpected question mark #17

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 Nov 8, 2016
Merged

Fixed 404 caused by unexpected question mark #17

merged 1 commit into from Nov 8, 2016

Conversation

ghost
Copy link

@ghost ghost commented Nov 3, 2016

Very simply, this pull request modifies certain files to escape symbols in filenames that may cause 404s unescaped.

@ghost ghost added the type/bug label Nov 3, 2016
@tboerger tboerger closed this Nov 3, 2016
@tboerger
Copy link
Member

tboerger commented Nov 3, 2016

Please reopen against master.

@tboerger tboerger added invalid and removed type/bug labels Nov 3, 2016
@bkcsoft bkcsoft changed the base branch from develop to master November 4, 2016 04:01
@bkcsoft bkcsoft reopened this Nov 4, 2016
@strk
Copy link
Member

strk commented Nov 4, 2016

Could you provide a testcase for the issue, or at least instructions to reproduce ?

@tboerger tboerger added this to the 1.0.0 milestone Nov 4, 2016
@ghost
Copy link
Author

ghost commented Nov 4, 2016

@strk It's a simple case of creating a file with '?' in the filename.

@@ -97,7 +97,7 @@ func NewFuncMap() []template.FuncMap {
"MD5": base.EncodeMD5,
"ActionContent2Commits": ActionContent2Commits,
"EscapePound": func(str string) string {
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20").Replace(str)
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand here what the dark red color on percent sign means, do you ?

Copy link
Author

Choose a reason for hiding this comment

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

It's not important, it's just invalid highlighting.

Copy link
Member

Choose a reason for hiding this comment

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

A better method is to define as a static replacer

var replacerEscapePound = strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F")

And then replace the two palces of references.

@bkcsoft
Copy link
Member

bkcsoft commented Nov 4, 2016

Quick question, doesn't golang have a URL_escape? :)

@strk
Copy link
Member

strk commented Nov 5, 2016 via email

@ghost
Copy link
Author

ghost commented Nov 6, 2016

Yet you can't use QueryEscape for filenames though.

@strk
Copy link
Member

strk commented Nov 6, 2016

Could the code duplication be avoided by putting the replace code in a common function ?
The code is currently duplicated in NewFuncMap (template/template.go) and editFilePost (routers/repo/editor.go)

@strk
Copy link
Member

strk commented Nov 6, 2016

Besides, I just tested reproducing and I go the 404 before and after applying your patch

@ghost
Copy link
Author

ghost commented Nov 7, 2016

@strk can you tell me what you did to get the 404?

@strk
Copy link
Member

strk commented Nov 7, 2016

I reloaded the URL I got the 404 from before the patch (url containing the ? sign). Now I realize I should have probably reloaded the previous page ? Will try again later.

@strk
Copy link
Member

strk commented Nov 7, 2016

Meanwhile please consider removing the code duplication, and maybe put the shared function under automatic testing

@strk
Copy link
Member

strk commented Nov 7, 2016

Ok, reloading the previous page gives the correct link. So LGTM (but code duplication would really be better to avoid)

@tboerger
Copy link
Member

tboerger commented Nov 7, 2016

LGTM

@DblK DblK added the lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. label Nov 8, 2016
This fixes 404 caused when creating new files or wiki pages with question marks. Amended to force CI rebuild
@codecov-io
Copy link

codecov-io commented Nov 8, 2016

Current coverage is 3.14% (diff: 100%)

Merging #17 into master will not change coverage

@@            master       #17   diff @@
========================================
  Files           33        33          
  Lines         7823      7823          
  Methods          0         0          
  Messages         0         0          
  Branches         0         0          
========================================
  Hits           246       246          
  Misses        7557      7557          
  Partials        20        20          

Powered by Codecov. Last update f6d53ec...01c5233

@metalmatze
Copy link
Contributor

LGTM

@metalmatze metalmatze merged commit 45c4539 into go-gitea:master Nov 8, 2016
@tboerger tboerger removed the lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. label Nov 11, 2016
@ghost ghost deleted the issue/3666 branch November 25, 2016 01:38
@tboerger tboerger added the lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. label Nov 29, 2016
@ghost ghost restored the issue/3666 branch December 11, 2016 05:39
lunny referenced this pull request in lunny/gitea Feb 7, 2019
* Avoid creating an array for the sole purpose of counting elements

Probably speeds up counting commits for git versions < 1.8.0,
although I dubt it would make a visible difference

* Fix commit count with git version < 1.8.0

With format='' the output does not end with a newline (checked)
lunny referenced this pull request in lunny/gitea Feb 7, 2019
Added real name of Bwko to maintainers file
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants