HomePhabricator

AjaxResponse: Fix broken logic for extracting HTTP status codes

Authored by bd808.

Description

AjaxResponse: Fix broken logic for extracting HTTP status codes

Follows-up 6584cef207 (r16266; 2006; MediaWiki 1.8.0).
This regex was just trimming whitespace from the start of the string. It
matched whitespace, then a match group for a first sequence of digits. The
replacement is just the digits match. This is essentially ltrim(). It didn't
account for the content after the match.

echo preg_replace( '/^ *(\d+)/', '\1', '200 OK' );
"200 OK"

This was causing:

Warning: Unknown HTTP status code 200 OK in libs/HttpStatus.php:100
Warning: Unknown HTTP status code 304 Not Modified OK in libs/HttpStatus.php:100

It defaults to HTTP 200. So presumbaly the impact was low. Though it may've caused
304 responses to have been broken (content body missing).

Bug: T102028
Change-Id: Iafff9982bbbee893c13f891901dde88f998db7a6