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

Refactor submodule URL parsing #7100

Merged
merged 2 commits into from
Jun 3, 2019
Merged

Refactor submodule URL parsing #7100

merged 2 commits into from
Jun 3, 2019

Conversation

mrsdizzie
Copy link
Member

Use combination of url.Parse and regex to parse refURL rather than by hand with indexes & attempt to check if refURL is from same instance and adjust output to match.

Also now return empty string instead of our original guess at URL if we are unable to parse it.

Fixes #1526

The logic behind comparing the refURL hostname with the prefixURL hostname is that if they are the same, we should use whatever the entire prefixURL host is when creating the link -- which allows us to take both the scheme and optional port number and return a more correct link.

For submodules from different hosts, I think it is still safe to create links (most github/gitlab/etc... will have corresponding web links).

Use combination of url.Parse and regex to parse refURL rather than by
hand with indexes & attempt to check if refURL is from same instance and
adjust output to match.

Also now return empty string instead of our original
guess at URL if we are unable to parse it.

Fixes go-gitea#1526
@codecov-io
Copy link

codecov-io commented Jun 1, 2019

Codecov Report

Merging #7100 into master will increase coverage by 0.02%.
The diff coverage is 91.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7100      +/-   ##
==========================================
+ Coverage   41.54%   41.57%   +0.02%     
==========================================
  Files         446      446              
  Lines       60825    60848      +23     
==========================================
+ Hits        25271    25297      +26     
+ Misses      32271    32268       -3     
  Partials     3283     3283
Impacted Files Coverage Δ
modules/git/submodule.go 75% <91.48%> (+28.33%) ⬆️
modules/log/file.go 75.52% <0%> (-2.1%) ⬇️
modules/log/event.go 64.46% <0%> (-1.53%) ⬇️
models/repo_list.go 73.09% <0%> (+1.01%) ⬆️

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 45f588e...513d946. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 1, 2019
@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 Jun 1, 2019
if urlPrefixHostname == refHostname {
return prefixURL.Scheme + "://" + urlPrefixHostname + path
}
return "http://" + refHostname + path
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it default to https better?

Copy link
Member Author

Choose a reason for hiding this comment

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

It wouldn't work if the server didn't support https (we don't know anything about it in this case). most servers should issue a redirect from http to https if they do support it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lafriks what do you think? I agree with @mrsdizzie here - most https sites will simply redirect http to https.

Copy link
Member

Choose a reason for hiding this comment

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

true but from security point of view it would be better to prefer https and as most of users should be running https this would result in unneeded http request to server.. So it is trade-off for security vs usability :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might need to add some repository configuration to allow for people to set their own conversions for submodules, but it's not particularly high priority.

@lafriks lafriks added the type/enhancement An improvement of existing functionality label Jun 1, 2019
@lafriks lafriks added this to the 1.9.0 milestone Jun 1, 2019
@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 Jun 3, 2019
@lunny lunny merged commit 2ac2a5b into go-gitea:master Jun 3, 2019
jeffliu27 pushed a commit to jeffliu27/gitea that referenced this pull request Jul 18, 2019
Use combination of url.Parse and regex to parse refURL rather than by
hand with indexes & attempt to check if refURL is from same instance and
adjust output to match.

Also now return empty string instead of our original
guess at URL if we are unable to parse it.

Fixes go-gitea#1526
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 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/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Submodule with custom ssh port shows incorrect link in Web UI
7 participants