Skip to content
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

Clarify the suffices and prefixes of setting.AppSubURL and setting.AppURL #12999

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Oct 1, 2020

In more than a couple of places we're slightly confused about whether AppURL and AppSubURL have preceding or trailing slashes.

This PR adds comments to the definition of the setting.App*, removes an old unused setting variable, uses the clarity obtained to simplify several uses of AppURL and AppSubURL and fixes a potential issue with a missing QuoteMeta in regexp.

Signed-off-by: Andrew Thornton art27@cantab.net

…pURL

Also removes some unnecessary uses of fmt.Sprintf and adds documentation
strings

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Oct 1, 2020
@zeripath
Copy link
Contributor Author

zeripath commented Oct 1, 2020

setting.AppSubURLDepth has been removed as it is not used.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 1, 2020
@codecov-commenter
Copy link

Codecov Report

Merging #12999 into master will decrease coverage by 0.00%.
The diff coverage is 35.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12999      +/-   ##
==========================================
- Coverage   42.59%   42.59%   -0.01%     
==========================================
  Files         671      671              
  Lines       73625    73619       -6     
==========================================
- Hits        31363    31357       -6     
+ Misses      37183    37181       -2     
- Partials     5079     5081       +2     
Impacted Files Coverage Δ
routers/admin/admin.go 11.45% <0.00%> (ø)
routers/api/v1/org/member.go 19.54% <0.00%> (+0.22%) ⬆️
routers/user/notification.go 40.17% <0.00%> (ø)
models/notification.go 65.76% <100.00%> (ø)
models/repo.go 55.15% <100.00%> (ø)
models/user.go 53.58% <100.00%> (ø)
modules/markup/html.go 78.61% <100.00%> (+0.26%) ⬆️
modules/setting/setting.go 47.50% <100.00%> (-0.12%) ⬇️
routers/repo/search.go 69.23% <100.00%> (-1.14%) ⬇️
modules/util/timer.go 42.85% <0.00%> (-42.86%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6da033...b2c29e2. Read the comment docs.

@zeripath zeripath added this to the 1.14.0 milestone Oct 1, 2020
@lafriks
Copy link
Member

lafriks commented Oct 2, 2020

Imho both appurl and appsuburl should end with / otherwise it will still be confusing and inconsistent

@zeripath
Copy link
Contributor Author

zeripath commented Oct 2, 2020

The reason that AppSubURL doesn't have a terminal / is because it allows it to be empty when there is no suburl.

That's quite nice actually and leads to very compact relative URLs and easy handling of AppSubURL with relative addresses. (Just prefix them with AppSubURL and it will always be right.)

AppURL will have a terminal slash for other similar reasons in that some proxies will likely only proxy the slash terminal address and I suspect that means that it's easier to and simpler to just write AppURL instead of AppURL+"/"

This PRs intention was not change behaviour but rather to clarify what is actually happenin, but if we were to change anything I'd argue we should not have the terminal / on the AppURL.

That would make creating the "relpath" and making the absolute URL the same: clean the path to root it on the AppSubURL then either prefix with suburl or the URL as appropriate.

@lafriks
Copy link
Member

lafriks commented Oct 5, 2020

I would prefer that non of them should have / at the end imho, this way AppURL + AppSubURL + /path is always valid

@zeripath
Copy link
Contributor Author

zeripath commented Oct 5, 2020

I would prefer that non of them should have / at the end imho, this way AppURL + AppSubURL + /path is always valid

AppURL has to contain the AppSubURL so I think you mean AppURL + "/path".

@lafriks
Copy link
Member

lafriks commented Oct 5, 2020

I would prefer that non of them should have / at the end imho, this way AppURL + AppSubURL + /path is always valid

AppURL has to contain the AppSubURL so I think you mean AppURL + "/path".

yes, I meant (AppURL || AppSubURL) + /path. So that you don't have to think if you need to add / before rest of url or not

@zeripath
Copy link
Contributor Author

zeripath commented Oct 5, 2020

As a (partially relevant) aside:

Do you know if there is ever a reason for Gitea to be producing non-FQDN urls that point outside of its own root? My suspicion is that there is not and that there should not be.

@lafriks
Copy link
Member

lafriks commented Oct 5, 2020

I don't know what did you mean by that but there should not be such urls

@codecov-io
Copy link

Codecov Report

Merging #12999 into master will increase coverage by 0.28%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12999      +/-   ##
==========================================
+ Coverage   41.96%   42.24%   +0.28%     
==========================================
  Files         683      683              
  Lines       75279    75375      +96     
==========================================
+ Hits        31589    31843     +254     
+ Misses      38524    38306     -218     
- Partials     5166     5226      +60     
Impacted Files Coverage Δ
routers/admin/admin.go 11.41% <0.00%> (ø)
routers/api/v1/org/member.go 19.54% <0.00%> (+0.22%) ⬆️
routers/repo/pull.go 33.29% <0.00%> (ø)
routers/user/notification.go 40.17% <0.00%> (ø)
models/notification.go 65.76% <100.00%> (ø)
models/repo.go 56.24% <100.00%> (ø)
models/user_avatar.go 31.57% <100.00%> (ø)
modules/markup/html.go 78.61% <100.00%> (+0.26%) ⬆️
modules/setting/setting.go 45.88% <100.00%> (-0.12%) ⬇️
routers/repo/search.go 69.23% <100.00%> (-1.14%) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b50448b...a87d7e4. Read the comment docs.

@stale
Copy link

stale bot commented Dec 25, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions.

@stale stale bot removed the issue/stale label Feb 12, 2021
@6543
Copy link
Member

6543 commented Feb 12, 2021

@uli-heller would you like to test now ?

@uli-heller
Copy link
Contributor

@6543 : I'll do so but I'm not sure it it will work out today. Still busy @work...

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 12, 2021
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 19, 2021
@6543
Copy link
Member

6543 commented Feb 19, 2021

🚀

@6543 6543 merged commit aa4f918 into go-gitea:master Feb 19, 2021
@go-gitea go-gitea locked and limited conversation to collaborators May 13, 2021
@zeripath zeripath deleted the setting.AppSubURL-is-defined-as-having-no-trailing-slash branch December 29, 2022 19:17
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/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants