From: Christian Couder Date: Fri, 03 Apr 2026 08:16:15 GMT Subject: Re: [PATCH 10/10] t5710: use proper file:// URIs for absolute paths Message-ID: In-Reply-To: On Thu, Apr 2, 2026 at 11:58 AM Junio C Hamano wrote: > > Christian Couder writes: > > > +# On Windows, 'pwd' returns a path like 'D:/foo/bar'. Prepend '/' to turn > > +# it into '/D:/foo/bar', which is what git expects in file:// URLs on Windows. > > +# On Unix, the path already starts with '/', so this is a no-op. > > +pwd_path=$(pwd) > > +case "$pwd_path" in > > +[a-zA-Z]:*) pwd_path="/$pwd_path" ;; > > +esac > > +PWD_URL="file://$pwd_path" > > +# Same as PWD_URL but with spaces percent-encoded, for use in URL patterns. > > +ENCODED_PWD_URL="file://$(echo "$pwd_path" | sed "s/ /%20/g")" > > Two comments. > > - I was a bit surprised that these are not given as functions but > as variables, as a caller that chdirs around in the trash > directory would want a URL that points at its current working > directory (the expectation is from "pwd" in the name PWD_URL). > But a variable based interface "Here is the URL that corresponds > to the trash directory" is OK and probably easier to use than > "give me the URL corresponding to my current working directory", > simply because it allows a caller to append some string to it to > come up with a URL for any subdirectory on its own without > actually going there. But in that case, the name PWD_URL would > become misleading, as it is PWD as of the moment the variable > gets defined, and the true meaning of the variable is not "URL > for the current directory", but "URL for the trash directory" is > more usable definition. Right. I will use something like the following then: TRASH_DIRECTORY_URL="file://$pwd_path" ENCODED_TRASH_DIRECTORY_URL="file://$encoded_path" > - Is it sufficient to only special case SP? My repository may be > $HOME/w/git.git, for example, and the trash repository may be > "$HOME/w/git.git/t/trash directory.t5710/", so you need to cope > with SP between "trash" and "directory" the test framework adds > (to force you to be careful), but the test framework does not > control what can be in the leading $HOME part. I think it's quite unlikely for users to have strange characters in $HOME, but OK let's be cautious and encode a larger set than just space characters. And to be extra safe, let's also skip all the tests if we detect a special character not in the larger set. So something like: # Allowed characters: alphanumeric, standard path/URI (_ . ~ / : -), and those percent-encoded below (% space = ; ,) case "$pwd_path" in *[!a-zA-Z0-9_.~/:%\ =,;-]*) skip_all="PWD contains unsupported special characters" test_done ;; esac encoded_path=$(printf "%s" "$pwd_path" | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/=/%3D/g' -e 's/;/%3B/g' -e 's/,/%2C/g')