Git fork

remote-curl: reencode http error messages

We currently recognize an error message with a content-type
"text/plain; charset=utf-16" as text, but we ignore the
charset parameter entirely. Let's encode it to
log_output_encoding, which is presumably something the
user's terminal can handle.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Jeff King and committed by
Junio C Hamano
fc1b774c d4241f52

+19 -7
+10 -7
remote-curl.c
··· 194 194 } 195 195 } 196 196 197 - static int show_http_message(struct strbuf *type, struct strbuf *msg) 197 + static int show_http_message(struct strbuf *type, struct strbuf *charset, 198 + struct strbuf *msg) 198 199 { 199 200 const char *p, *eol; 200 201 201 202 /* 202 203 * We only show text/plain parts, as other types are likely 203 204 * to be ugly to look at on the user's terminal. 204 - * 205 - * TODO should handle "; charset=XXX", and re-encode into 206 - * logoutputencoding 207 205 */ 208 206 if (strcmp(type->buf, "text/plain")) 209 207 return -1; 208 + if (charset->len) 209 + strbuf_reencode(msg, charset->buf, get_log_output_encoding()); 210 210 211 211 strbuf_trim(msg); 212 212 if (!msg->len) ··· 225 225 { 226 226 struct strbuf exp = STRBUF_INIT; 227 227 struct strbuf type = STRBUF_INIT; 228 + struct strbuf charset = STRBUF_INIT; 228 229 struct strbuf buffer = STRBUF_INIT; 229 230 struct strbuf refs_url = STRBUF_INIT; 230 231 struct strbuf effective_url = STRBUF_INIT; ··· 249 250 250 251 memset(&options, 0, sizeof(options)); 251 252 options.content_type = &type; 253 + options.charset = &charset; 252 254 options.effective_url = &effective_url; 253 255 options.base_url = &url; 254 256 options.no_cache = 1; ··· 259 261 case HTTP_OK: 260 262 break; 261 263 case HTTP_MISSING_TARGET: 262 - show_http_message(&type, &buffer); 264 + show_http_message(&type, &charset, &buffer); 263 265 die("repository '%s' not found", url.buf); 264 266 case HTTP_NOAUTH: 265 - show_http_message(&type, &buffer); 267 + show_http_message(&type, &charset, &buffer); 266 268 die("Authentication failed for '%s'", url.buf); 267 269 default: 268 - show_http_message(&type, &buffer); 270 + show_http_message(&type, &charset, &buffer); 269 271 die("unable to access '%s': %s", url.buf, curl_errorstr); 270 272 } 271 273 ··· 310 312 strbuf_release(&refs_url); 311 313 strbuf_release(&exp); 312 314 strbuf_release(&type); 315 + strbuf_release(&charset); 313 316 strbuf_release(&effective_url); 314 317 strbuf_release(&buffer); 315 318 last_discovery = last;
+4
t/lib-httpd/error.sh
··· 15 15 printf "text/plain; charset=utf-8" 16 16 charset=utf-8 17 17 ;; 18 + *utf16*) 19 + printf "text/plain; charset=utf-16" 20 + charset=utf-16 21 + ;; 18 22 esac 19 23 printf "\n" 20 24
+5
t/t5550-http-fetch-dumb.sh
··· 186 186 grep "this is the error message" stderr 187 187 ' 188 188 189 + test_expect_success 'http error messages are reencoded' ' 190 + test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr && 191 + grep "this is the error message" stderr 192 + ' 193 + 189 194 stop_httpd 190 195 test_done