-
Notifications
You must be signed in to change notification settings - Fork 59
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
fix: Mount URL with spaces #137
Conversation
Fix for #86 |
Yes this is a good idea. |
src/util.c
Outdated
lprintf(fatal, "URL too long: %s\n", url); | ||
} | ||
if (url[i] == escape_me) { | ||
switch (c) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a switch statement here?
src/util.h
Outdated
/** | ||
* \brief URL characters that can be escaped | ||
*/ | ||
typedef enum { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we specify the actual list of characters that can be escaped here? This is very indirect.
src/link.c
Outdated
@@ -77,10 +77,15 @@ static CURL *Link_to_curl(Link *link) | |||
if (ret) { | |||
lprintf(error, "%s", curl_easy_strerror(ret)); | |||
} | |||
ret = curl_easy_setopt(curl, CURLOPT_URL, link->f_url); | |||
|
|||
char *escaped_spaces = escape_char(link->f_url, ESCAPED_CHAR_SPACE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have difficulty with understanding what ESCAPED_CHAR_SPACE
gets evaluated to.
src/util.c
Outdated
|
||
switch (c) { | ||
case ESCAPED_CHAR_SPACE: | ||
escape_me = ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a good idea, the characters that need to be escape is not going to change on the fly. You should define it globally, rather than creating a new type to wrap around it. I don't think we need this many indirection.
@fangfufu Replying all comments as @EyitopeIO I would look for examples on how to reduce/remove the indirection and update in a bit. I'm just recalling that I've seen good example in libnetfilter_conntrack when updating patches. |
Could you point me to your example please? All I am suggesting is that we don't unnecessarily define new types. I understand you might want to do what you did when there might be multiple characters that need to be escaped, but this is not the case here. |
@fangfufu I've added eb274b3 to address unresolved issues. I hope I understood them correctly. Please don't hesitate to let me know as I'm willing to adapt and learn. I also tested this by setting |
Please could you squash your 3 commits together into one commit, your 3 commits are all addressing the same issue. It really should be squashed together. In future consider using |
src/util.c
Outdated
@@ -49,6 +49,53 @@ char *path_append(const char *path, const char *filename) | |||
return str; | |||
} | |||
|
|||
char *escape_char(const char *url, const char escape_me) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are only escaping a single space character, please rename this function into escape_space
or something. and remove the escape_me
variable.
src/util.c
Outdated
if (escape_me == ' ') { | ||
replacement = "%20"; | ||
} else { | ||
lprintf(warning, "Not escaping: '%c' in URL\n", escape_me); | ||
return NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer necessary.
src/util.h
Outdated
/** | ||
* \brief escape a single character in a URL | ||
* \details This function escapes a character a URL and returns a pointer to | ||
* the string with the escaped character. We don't use curl_easy_escape() on | ||
* the entire URL because it would break the URL. For example, 'http://a c' | ||
* becomes 'http:%2F%2Fa%20c', escaping more characters than we want. | ||
* \note You need to free the char * after use. | ||
*/ | ||
char *escape_char(const char *s, const char c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rewrite the description to escaping only the space character.
8f0b787
to
27ecec6
Compare
@fangfufu |
src/util.c
Outdated
@@ -49,6 +49,47 @@ char *path_append(const char *path, const char *filename) | |||
return str; | |||
} | |||
|
|||
char *escape_spaces(const char *path) | |||
{ | |||
char space = ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this variable. Remove please. ' '
has fewer characters than space
.
Actually I have an important question, why don't we use |
@fangfufu Using Ideally, I think you'd want to so So originally my thinking was to have a function that behaves like the libcurl function, but allows you specify what you want to escape. |
No, in this situation you should not be writing code that duplicate what libcurl does. You can remove the protocol part of the URL, please refer to Have a look at https://curl.se/libcurl/c/curl_easy_getinfo.html I am sorry but I don't like the current implementation, as it is a hack for the space character. |
Just for the record, this is for fixing #138 |
|
@fangfufu Let's say we want to mount If we now want to mount Now that you mention it, changes so far sure looks like a hack for just the space character. I think the links could be sanitised (escaping funny characters) from within the function LinkTable_uninitialised_fill instead of in function LinkTable_fill, since both single-file mode and normal mode take a path to Lastly, if a user specified a path Truth is I don't really know what I'm doing and just guessing. |
@EyitopeIO, I have given you the function that is used to escape percent-encoding which is |
There is also |
Okay, I'd try one more time but with the understanding that the fix should generally address characters that could break URLs (e.g. in the related issues), and not just a hack for the space character. |
To prevent PR from being too large, the path resolution was kept separate and not merged into one. I thought perhaps this would be a refactoring for later. Looking forward to the review and what to change.
Tests on Ubuntu 22