Fix URL building for default repo branch API #1

Merged
ben merged 1 commits from lucidiot/tildepages:fix-default-branch-url into main 2022-07-20 16:24:58 +00:00
Contributor

I found a bug when trying to use a repo on an organization at https://tildegit.org/casa/pages where the site could be accessed via https://casa.tildepages.org/@main/ but not https://casa.tildepages.org/. Using a pages branch or any other name did not do anything.

It turns out the issue comes from this bit.

Using the base URL (giteaRoot) in path.Join caused it to remove the two slashes (because /////tmp == /tmp):

https:/tildegit.org/api/v1/repos/owner/name

Then, using that in URL.Parse causes it to see a https: scheme, and the / right afterwards means "start a path here", not a hostname, because hostnames begin with two slashes. That's a valid URL, with no hostname. Then it gets turned back into a string:

https:///tildegit.org/api/v1/repos/owner/name

That's another way of expressing the same URL with no hostname: <scheme>://<empty hostname>/<path>.

curl, Firefox and Chromium all fix the triple slash automatically, but fasthttp doesn't, and it tries to look up the empty string as a DNS host!

⚠️ Note that I am making this PR without testing it locally or anything because I'm at work and just wanted to show a probable fix :p

I found a bug when trying to use a repo on an organization at https://tildegit.org/casa/pages where the site could be accessed via https://casa.tildepages.org/@main/ but not https://casa.tildepages.org/. Using a `pages` branch or any other name did not do anything. It turns out the issue comes from [this bit](https://tildegit.org/tildeverse/tildepages/src/commit/1955acce0519521ef0b01dd8dda10a28befb5edb/server/upstream/gitea.go#L67). Using the base URL (`giteaRoot`) in path.Join caused it to remove the two slashes (because /////tmp == /tmp): `https:/tildegit.org/api/v1/repos/owner/name` Then, using that in URL.Parse causes it to see a `https:` scheme, and the / right afterwards means "start a path here", not a hostname, because hostnames begin with two slashes. That's a valid URL, with no hostname. Then it gets turned back into a string: `https:///tildegit.org/api/v1/repos/owner/name` That's another way of expressing the same URL with no hostname: `<scheme>://<empty hostname>/<path>`. curl, Firefox and Chromium all fix the triple slash automatically, but fasthttp doesn't, and it tries to look up the empty string as a DNS host! :warning: Note that I am making this PR without testing it locally or anything because I'm at work and just wanted to show a probable fix :p
lucidiot added 1 commit 2022-07-20 16:24:05 +00:00
d84955e6cd Fix URL building for default repo branch API
Using the base URL in path.Join caused it to remove the two slashes (because /////tmp == /tmp):

`https:/tildegit.org/api/v1/repos/owner/name`

Then, using that in URL.Parse causes it to see a `https:` scheme, and the / right afterwards means "start a path here", not a hostname, because hostnames begin with two slashes. That's a valid URL, with no hostname. Then it gets turned back into a string:

`https:///tildegit.org/api/v1/repos/owner/name`

That's another way of expressing the same URL with no hostname: //<empty hostname>/<path>.

curl, Firefox and Chromium all fix the triple slash automatically, but fasthttp doesn't, and it tries to look up the empty string as a DNS host!
ben merged commit d84955e6cd into main 2022-07-20 16:24:58 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: tildeverse/tildepages#1
No description provided.