Commit 71c27cb3 authored by Jo-Philipp Wich's avatar Jo-Philipp Wich
Browse files

file_util: implement urldecode_path()



Introduce a new urldecode_path() helper to resolve percent-encoded URL
portions back into the original binary form.

Signed-off-by: default avatarJo-Philipp Wich <jo@mein.io>
parent d1fe095d
......@@ -395,3 +395,23 @@ char *urlencode_path(const char *filename)
return (char *)copy;
}
char *urldecode_path(const char *filename)
{
unsigned char *copy = (unsigned char *)xstrdup(filename);
unsigned char *in, *out;
for (in = copy, out = copy; *in != 0; in++) {
if (*in == '%' && isxdigit(in[1]) && isxdigit(in[2])) {
*out++ = hex2bin(in[1]) * 16 + hex2bin(in[2]);
in += 2;
}
else {
*out++ = *in;
}
}
*out = 0;
return (char *)copy;
}
......@@ -32,5 +32,6 @@ char *checksum_bin2hex(const char *src, size_t len);
char *checksum_hex2bin(const char *src, size_t *len);
char *urlencode_path(const char *filename);
char *urldecode_path(const char *filename);
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment