diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-05-05 18:18:36 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-05-05 20:02:20 +0200 |
commit | 8219259c39f19f45c2f094a6ba7930f940b1074a (patch) | |
tree | d6b654c99a91f119c66bd805d5ab28c0807d922f /source/fitz | |
parent | 3d81ce6e34e6216b4ec67deee50aab60097a52b0 (diff) | |
download | mupdf-8219259c39f19f45c2f094a6ba7930f940b1074a.tar.xz |
epub: Decode URL escapes in epub paths.
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/string.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/source/fitz/string.c b/source/fitz/string.c index 224eeff7..820a4426 100644 --- a/source/fitz/string.c +++ b/source/fitz/string.c @@ -84,6 +84,44 @@ fz_dirname(char *dir, const char *path, int n) dir[i+1] = 0; } +static int ishex(int a) +{ + return (a >= 'A' && a <= 'F') || + (a >= 'a' && a <= 'f') || + (a >= '0' && a <= '9'); +} + +static int tohex(int c) +{ + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 0xA; + if (c >= 'A' && c <= 'F') return c - 'A' + 0xA; + return 0; +} + +char * +fz_urldecode(char *url) +{ + char *s = url; + char *p = url; + while (*s) + { + int c = (unsigned char) *s++; + if (c == '%' && ishex(s[0]) && ishex(s[1])) + { + int a = tohex(*s++); + int b = tohex(*s++); + *p++ = a << 4 | b; + } + else + { + *p++ = c; + } + } + *p = 0; + return url; +} + #define SEP(x) ((x)=='/' || (x) == 0) char * @@ -139,6 +177,7 @@ fz_cleanname(char *name) *q = '\0'; return name; } + enum { UTFmax = 4, /* maximum bytes per rune */ |