From 0af4d3e953357563b3407878b6949743111719a0 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Wed, 5 Jul 2017 00:46:27 +0200 Subject: Fix parsing of hex escapes in file URIs This fixes round-trip of paths to/from escaped file URIs. --- src/serd_internal.h | 7 +++++++ src/uri.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/serd_internal.h b/src/serd_internal.h index aa5b3c53..afbea5fb 100644 --- a/src/serd_internal.h +++ b/src/serd_internal.h @@ -294,6 +294,13 @@ is_digit(const uint8_t c) return in_range(c, '0', '9'); } +/* RFC2234: HEXDIG ::= DIGIT / "A" / "B" / "C" / "D" / "E" / "F" */ +static inline bool +is_hexdig(const uint8_t c) +{ + return is_digit(c) || in_range(c, 'A', 'F'); +} + static inline bool is_space(const char c) { diff --git a/src/uri.c b/src/uri.c index 543b2305..7b172e42 100644 --- a/src/uri.c +++ b/src/uri.c @@ -78,7 +78,7 @@ serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname) if (*(s + 1) == '%') { serd_chunk_sink("%", 1, &chunk); ++s; - } else if (is_digit(*(s + 1)) && is_digit(*(s + 2))) { + } else if (is_hexdig(*(s + 1)) && is_hexdig(*(s + 2))) { const uint8_t code[3] = { *(s + 1), *(s + 2), 0 }; uint32_t num; sscanf((const char*)code, "%X", &num); -- cgit v1.2.1