Skip to content

Encode spaces in URL output #2386

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

Merged
merged 1 commit into from
Mar 26, 2018
Merged

Conversation

HebaruSan
Copy link
Member

Problem

Currently in the output for NetKAN pull request validation, the download URLs are printed with spaces unescaped:

image

This trips up the Jenkins site's attempt to make the URLs clickable, which could be handy if someone investigating an issue wants to inspect the downloaded files locally. Only the part leading up to the first space is detected, which isn't the full URL that's being downloaded.

Changes

Now we replace spaces in this output with %20 as per standard URL encoding.

I looked into the proper functions for encoding URLs in C#, and none of them seemed appropriate for this. The problem is that Uri.ToString() outputs a partially valid URL (correctly formatted but may contain spaces), which none of the various encoding functions expect. Some of them would encode the :// part as %3A%2F%2F, which we definitely don't want, and the rest would miss the spaces. So I just went with .Replace.

This change affects only these specific output statements; no changes are made to the internals of URL handling for downloads, metadata, etc.

Trivia

You may be familiar with the practice of encoding spaces in URLs as +. TIL that this is only valid in the keys and values of form fields, but not in the base URL to which those keys and values are sent (or anywhere in non-form URLs)! This is why I went with %20 in this case.

@HebaruSan HebaruSan added Easy This is easy to fix Cmdline Issues affecting the command line Network Issues affecting internet connections of CKAN labels Mar 24, 2018

Verified

This commit was signed with the committer’s verified signature. The key has expired.
andir Andreas Rammhold
@politas
Copy link
Member

politas commented Mar 24, 2018

What does url.value return?

@HebaruSan
Copy link
Member Author

HebaruSan commented Mar 24, 2018

What does url.value return?

A compiler error, because there is no such property (I tried both value and Value):

  Net\NetAsyncDownloader.cs(167,38): error CS1061: 'Uri' does not contain a definition for 'value' and no extension method 'value' accepting a fi
rst argument of type 'Uri' could be found (are you missing a using directive or an assembly reference?) [C:\Users\Paul\github\CKAN\Core\CKAN-core
.csproj]

  Net\NetAsyncDownloader.cs(167,38): error CS1061: 'Uri' does not contain a definition for 'Value' and no extension method 'Value' accepting a fi
rst argument of type 'Uri' could be found (are you missing a using directive or an assembly reference?) [C:\Users\Paul\github\CKAN\Core\CKAN-core
.csproj]

Sorry, something went wrong.

@politas
Copy link
Member

politas commented Mar 24, 2018

Ah, because they are System.uri rather than System.Security.Policy.url

Sorry, something went wrong.

@politas politas merged commit de33f15 into KSP-CKAN:master Mar 26, 2018
politas added a commit that referenced this pull request Mar 26, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@politas politas removed the Network Issues affecting internet connections of CKAN label Mar 26, 2018
@HebaruSan HebaruSan deleted the fix/url-spaces branch March 27, 2018 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmdline Issues affecting the command line Easy This is easy to fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants