-
Notifications
You must be signed in to change notification settings - Fork 14
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
Question about the code #3
Comments
Hey! This is a really good question. I wrote this years ago so I had to look at my code again to see what I might have been thinking. The code seems to be decoding the string until there's nothing left to decode, which could decode something that was doubly encoded. Try decoding the string What I did here actually violates the spec, so that's too bad.
I didn't actually know about that clause previously. I'll keep this issue open to represent the problem of continuously decoding strings. Feel free to submit a Pull Request that resolves this issue. Perhaps strings can be optionally decoded recursively? I hope that helps! |
Thanks for the clarification!! 😃 |
Here's my simplified version, that:
Note: since it's overwriting the original buffer, if you want to keep the original url you'll need to make a copy yourself int urlDecode(char *dStr) {
int i, j;
char hex[] = "00"; /* for a hex code */
for(i=0, j=0; dStr[i]; i++, j++)
{
if(dStr[i] != '%' || dStr[i+1] == 0)
{
dStr[j] = dStr[i];
continue;
}
if(isxdigit(dStr[i+1]) && isxdigit(dStr[i+2]))
{
/* combine the next two numbers into one */
hex[0] = dStr[i+1];
hex[1] = dStr[i+2];
/* convert it to decimal */
dStr[j] = strtol(hex, NULL, 16);
i += 2; /* move to the end of the hex */
}
}
dStr[j] = 0; /* null terminate the string */
return (i != j);
} |
Hello! :)
I have this doubt about your code
In the file:line urldecode.c:15
What is the purpose of have a nested loop ?
I thought that one is enough. Why perform another decode when you already did one ?
This is for achieve something of the standard rfc that I'm missing out ?
Thanks in advance!!!
The text was updated successfully, but these errors were encountered: