diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 98981c0ae32..c0e02664eeb 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1689,9 +1689,9 @@ static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{ len = p - h->header; } if (len > 0) { - do { + while (len != 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t')) { len--; - } while (len != 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t')); + } if (len) { s = do_alloca(len + 1, use_heap); memcpy(s, h->header, len); diff --git a/sapi/cgi/tests/apache_response_headers.phpt b/sapi/cgi/tests/apache_response_headers.phpt new file mode 100644 index 00000000000..2964ac7bc71 --- /dev/null +++ b/sapi/cgi/tests/apache_response_headers.phpt @@ -0,0 +1,48 @@ +--TEST-- +apache_response_headers() +--SKIPIF-- + +--FILE-- + +'; + +file_put_contents( $test_file, $code ); + +passthru( "$php -n -q " . escapeshellarg( $test_file ) ); + +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +array(3) { + ["X-Powered-By"]=> + string(%d) "PHP/%s" + ["X-Robots-Tag"]=> + string(26) "noindex,nofollow,noarchive" + ["Content-type"]=> + string(24) "text/html; charset=UTF-8" +} +===DONE===