Skip to content

Commit a02ad88

Browse files
committed
Merge branch 'ye/http-extract-charset'
* ye/http-extract-charset: http: fix charset detection of extract_content_type()
2 parents 6293aea + f34a655 commit a02ad88

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ static int extract_param(const char *raw, const char *name,
927927
return -1;
928928
raw++;
929929

930-
while (*raw && !isspace(*raw))
930+
while (*raw && !isspace(*raw) && *raw != ';')
931931
strbuf_addch(out, *raw++);
932932
return 0;
933933
}
@@ -971,7 +971,7 @@ static void extract_content_type(struct strbuf *raw, struct strbuf *type,
971971

972972
strbuf_reset(charset);
973973
while (*p) {
974-
while (isspace(*p))
974+
while (isspace(*p) || *p == ';')
975975
p++;
976976
if (!extract_param(p, "charset", charset))
977977
return;

t/lib-httpd/error.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ case "$PATH_INFO" in
1919
printf "text/plain; charset=utf-16"
2020
charset=utf-16
2121
;;
22+
*odd-spacing*)
23+
printf "text/plain; foo=bar ;charset=utf-16; other=nonsense"
24+
charset=utf-16
25+
;;
2226
esac
2327
printf "\n"
2428

t/t5550-http-fetch-dumb.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,10 @@ test_expect_success 'http error messages are reencoded' '
191191
grep "this is the error message" stderr
192192
'
193193

194+
test_expect_success 'reencoding is robust to whitespace oddities' '
195+
test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
196+
grep "this is the error message" stderr
197+
'
198+
194199
stop_httpd
195200
test_done

0 commit comments

Comments
 (0)