diff options
author | Omar Polo <op@omarpolo.com> | 2022-07-04 09:31:36 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2022-07-04 09:31:36 +0000 |
commit | f2f8eb35c86c4e1c1d858e782c864deac0511cd3 (patch) | |
tree | 93fa5ddc61c2ade321e1eeeabfe0d50d8b938b4b /iri.c | |
parent | 3bd4a6dea08fc977e314877cefed1c6fdd6b1613 (diff) |
encode file names in the directory index
Spotted the hard way by cage
Diffstat (limited to 'iri.c')
-rw-r--r-- | iri.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -444,6 +444,43 @@ serialize_iri(struct iri *i, char *buf, size_t len) return l < len; } +int +encode_path(char *buf, size_t len, const char *path) +{ + char *p = buf; + int a, b; + + memset(buf, 0, len); + while (*path != '\0') { + if (len == 1) /* NUL */ + return -1; + + if (unreserved(*path) || + sub_delimiters(*path) || + *path == '@' || + *path == ':' || + *path == '/') { + *p++ = *path++; + len--; + } else if (len < 4) + return -1; + else { + a = (*path & 0xF0) >> 4; + b = (*path & 0x0F); + + p[0] = '%'; + p[1] = a <= 9 ? ('0' + a) : ('7' + a); + p[2] = b <= 9 ? ('0' + b) : ('7' + b); + + path++; + p += 3; + len -= 3; + } + } + + return 0; +} + char * pct_decode_str(char *s) { |