Skip to content

Conversation

@bk2204
Copy link
Member

@bk2204 bk2204 commented Jun 21, 2023

When we want to handle a local path, we must rewrite it internally into a file:/// URL, because we dispatch our standalone transfer agent based on the URL scheme. However, once we've looked up an appropriate URL and formatted it as the scheme prefers, if it contains a trailing slash, we ignore the entire lookup and replace the URL with the raw one given, but without the trailing slash.

This behaviour seems a bit bizarre, and it causes us to take a local path with a trailing slash and treat it not as the file:/// URL it needs to be, but as a raw local path, which gets refused. Let's avoid this problem by looking at the rewritten URL, and modifying that instead if we find its trailing slash to be offensive.

Fixes #5400
/cc @ebardsley as reporter

@bk2204 bk2204 marked this pull request as ready for review June 21, 2023 16:12
@bk2204 bk2204 requested a review from a team as a code owner June 21, 2023 16:12
@bk2204 bk2204 changed the title Local path trailing slash Handle local paths with trailing slashes Jun 21, 2023
Copy link
Member

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

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

Looks good! I had a suggestion about the tests only. Thanks!

bk2204 added 2 commits June 21, 2023 17:42
We'd like to use some of this test code in another test, so let's move
it out into a function we can call.  Right now, this results in no
changes to the code, but we'll make some in a future commit.
When we want to handle a local path, we must rewrite it internally into
a `file:///` URL, because we dispatch our standalone transfer agent
based on the URL scheme.  However, once we've looked up an appropriate
URL and formatted it as the scheme prefers, if it contains a trailing
slash, we ignore the entire lookup and replace the URL with the raw one
given, but without the trailing slash.

This behaviour seems a bit bizarre, and it causes us to take a local
path with a trailing slash and treat it not as the `file:///` URL it
needs to be, but as a raw local path, which gets refused.  Let's avoid
this problem by looking at the rewritten URL, and modifying that instead
if we find its trailing slash to be offensive.
@bk2204 bk2204 force-pushed the local-path-trailing-slash branch from d89fa0f to 600132c Compare June 21, 2023 17:43

if strings.HasSuffix(rawurl, "/") {
ep.Url = rawurl[0 : len(rawurl)-1]
if strings.HasSuffix(ep.Url, "/") {

Choose a reason for hiding this comment

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

Thanks for the quick fix! strings.TrimSuffix would be appropriate here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a good idea, but I'm going to leave this as it stands for now in the interests of making the minimum possible fix.

@bk2204 bk2204 merged commit 300f4ed into git-lfs:main Jun 21, 2023
@bk2204 bk2204 deleted the local-path-trailing-slash branch June 21, 2023 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloning local repo with trailing slash fails

3 participants