From 405853e84f21e22bdad0cf4736182a0dc361d849 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 7 Oct 2013 14:15:13 +0200 Subject: [PATCH] Fix decoding of charset inside Content-Type YAZ-701 --- src/srwutil.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/srwutil.c b/src/srwutil.c index 178d886..ef8eead 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -241,14 +241,19 @@ static void grab_charset(ODR o, const char *content_type, char **charset) const char *charset_p = 0; if (content_type && (charset_p = strstr(content_type, "; charset="))) { - int i = 0; - charset_p += 10; - while (i < 20 && charset_p[i] && - !strchr("; \n\r", charset_p[i])) - i++; - *charset = (char*) odr_malloc(o, i+1); - memcpy(*charset, charset_p, i); - (*charset)[i] = '\0'; + int j = 0, i = 0; + int sep = 0; + charset_p += 10; /* skip ; charset= */ + if (charset_p[i] == '"' || charset_p[i] == '\'') + sep = charset_p[i++]; + *charset = odr_strdup(o, charset_p); + while (charset_p[i] && charset_p[i] != sep) + { + if (charset_p[i] == '\\' && charset_p[i+1]) + i++; + (*charset)[j++] = charset_p[i++]; + } + (*charset)[j] = '\0'; } } } -- 1.7.10.4