-rw-r--r-- | parsing.c | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -101,17 +101,21 @@ char *parse_user(char *t, char **name, char **email, unsigned long *date) #else const char *reencode(char **txt, const char *src_enc, const char *dst_enc) { char *tmp; if (!txt || !*txt || !src_enc || !dst_enc) return *txt; - tmp = reencode_string(*txt, src_enc, dst_enc); + /* no encoding needed if src_enc equals dst_enc */ + if(!strcasecmp(src_enc, dst_enc)) + return *txt; + + tmp = reencode_string(*txt, dst_enc, src_enc); if (tmp) { free(*txt); *txt = tmp; } return *txt; } #endif @@ -155,16 +159,20 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) p += 9; t = strchr(p, '\n'); if (t) { ret->msg_encoding = substr(p, t + 1); p = t + 1; } } + /* if no special encoding is found, assume UTF-8 */ + if(!ret->msg_encoding) + ret->msg_encoding = xstrdup("UTF-8"); + // skip unknown header fields while (p && *p && (*p != '\n')) { p = strchr(p, '\n'); if (p) p++; } // skip empty lines between headers and message @@ -184,24 +192,22 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) if (p) p++; } if (p) ret->msg = xstrdup(p); } else ret->subject = xstrdup(p); - if (ret->msg_encoding) { - reencode(&ret->author, PAGE_ENCODING, ret->msg_encoding); - reencode(&ret->author_email, PAGE_ENCODING, ret->msg_encoding); - reencode(&ret->committer, PAGE_ENCODING, ret->msg_encoding); - reencode(&ret->committer_email, PAGE_ENCODING, ret->msg_encoding); - reencode(&ret->subject, PAGE_ENCODING, ret->msg_encoding); - reencode(&ret->msg, PAGE_ENCODING, ret->msg_encoding); - } + reencode(&ret->author, ret->msg_encoding, PAGE_ENCODING); + reencode(&ret->author_email, ret->msg_encoding, PAGE_ENCODING); + reencode(&ret->committer, ret->msg_encoding, PAGE_ENCODING); + reencode(&ret->committer_email, ret->msg_encoding, PAGE_ENCODING); + reencode(&ret->subject, ret->msg_encoding, PAGE_ENCODING); + reencode(&ret->msg, ret->msg_encoding, PAGE_ENCODING); return ret; } struct taginfo *cgit_parse_tag(struct tag *tag) { void *data; |