From: Bryan Davis Date: Thu, 11 Jun 2015 15:13:00 +0000 (-0600) Subject: AjaxResponse: Fix broken logic for extracting HTTP status codes X-Git-Tag: 1.31.0-rc.0~11115 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=7b6890654a3ef994eb12acd2f37e93d964878288;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php index b3a6573ba6..2984c33a56 100644 --- a/includes/AjaxResponse.php +++ b/includes/AjaxResponse.php @@ -86,7 +86,7 @@ class AjaxResponse { $this->mDisabled = false; $this->mText = ''; - $this->mResponseCode = '200 OK'; + $this->mResponseCode = 200; $this->mLastModified = false; $this->mContentType = 'application/x-wiki'; @@ -158,7 +158,11 @@ class AjaxResponse { */ function sendHeaders() { if ( $this->mResponseCode ) { - $n = preg_replace( '/^ *(\d+)/', '\1', $this->mResponseCode ); + // For back-compat, it is supported that mResponseCode be a string like " 200 OK" + // (with leading space and the status message after). Cast response code to an integer + // to take advantage of PHP's conversion rules which will turn " 200 OK" into 200. + // http://php.net/string#language.types.string.conversion + $n = intval( trim( $this->mResponseCode ) ); HttpStatus::header( $n ); } @@ -246,7 +250,7 @@ class AjaxResponse { $ismodsince >= $wgCacheEpoch ) { ini_set( 'zlib.output_compression', 0 ); - $this->setResponseCode( "304 Not Modified" ); + $this->setResponseCode( 304 ); $this->disable(); $this->mLastModified = $lastmod;