diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Replace the stray bytes of text that is not UTF-8
A commit whose encoding header names something iconv cannot convert,
or whose text is labelled UTF-8 without being it, reached a page
declared UTF-8 with its bytes untouched. The atom feed already
replaced them, so its UTF-8 reader moves to shared.c and every ident,
subject, message and tag text passes through it.
Diffstat (limited to 'source/parsing.c')
| -rw-r--r-- | source/parsing.c | 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 18 insertions, 9 deletions
diff --git a/source/parsing.c b/source/parsing.c index 655973b..8aa0ee4 100644 --- a/source/parsing.c +++ b/source/parsing.c @@ -92,8 +92,11 @@ static int end_of_header(const char *p) } /* - * A git built without iconv still offers reencode_string, where it always - * fails, so the field is left in whatever encoding it arrived in. + * Converts a field into the page encoding, which is UTF-8. A git built + * without iconv still offers reencode_string, where it always fails, and a + * field can be labelled UTF-8 without being it, so whatever is left that is + * not UTF-8 has its stray bytes replaced, and a page declared UTF-8 never + * carries any. */ static const char *reencode(char **text, const char *from, const char *to) { @@ -102,14 +105,14 @@ static const char *reencode(char **text, const char *from, const char *to) if (!*text || !from || !to) return *text; - if (!strcasecmp(from, to)) - return *text; - - converted = reencode_string(*text, to, from); - if (converted) { - free(*text); - *text = converted; + if (strcasecmp(from, to)) { + converted = reencode_string(*text, to, from); + if (converted) { + free(*text); + *text = converted; + } } + cgit_utf8_sanitize(*text); return *text; } @@ -256,6 +259,12 @@ struct taginfo *cgit_parse_tag(struct tag *tag) if (p && *p) info->msg = xstrdup(p); + // A tag carries no encoding header, so its text is taken as UTF-8 and + // cleaned the way a commit's is. + cgit_utf8_sanitize(info->tagger); + cgit_utf8_sanitize(info->tagger_email); + cgit_utf8_sanitize(info->msg); + cleanup: free(data); return info; |
