diff --git a/httpresponse.class.php b/httpresponse.class.php index 9686f86..5dc02cf 100644 --- a/httpresponse.class.php +++ b/httpresponse.class.php @@ -55,13 +55,14 @@ function __construct($status_code = null) { public function __get($k){ return $this->$k; } + public function __set($k, $v){ if($k=='body' AND $this->content_is_gzip_encoded()){ - //strip the gzip header - if(ord($v[0]) == 0x1f && ord($v[1]) == 0x8b) - { - $v = substr($v,10); - $v = gzinflate($v); + //strip the gzip header, explicitly suppressing errors + if(ord(@$v[0]) == 0x1f && ord(@$v[1]) == 0x8b) + { + $v = substr($v,10); + $v = gzinflate($v); } } $this->$k=$v; diff --git a/store.class.php b/store.class.php index eaa31a9..02f06e3 100644 --- a/store.class.php +++ b/store.class.php @@ -297,5 +297,4 @@ function mirror_from_url($url, $rdf_content=false) } } -?> - +?> \ No newline at end of file diff --git a/tests/httpresponse.test.php b/tests/httpresponse.test.php index 9bc5126..e258a60 100644 --- a/tests/httpresponse.test.php +++ b/tests/httpresponse.test.php @@ -6,15 +6,31 @@ class HttpResponseTest extends PHPUnit_Framework_TestCase { + private $old_error_reporting = 0; + + // switch off error suppression while we test test_set_body_empty + // because the error reporting in an end-user environment can't be guaranteed + // after the tests, restore the error reporting + + function setUp() { + $this->old_error_reporting = error_reporting(); + error_reporting(E_ALL); + } + + function tearDown() { + error_reporting($this->old_error_reporting); + } + + function test_set_body_with_empty_string(){ - function test_get_content_type(){ + $response = new HttpResponse(200); + + $headers = array(); + $headers['content-encoding'] = 'gzip'; + $response->headers = $headers; + $response->body = ""; - $response = new HttpResponse('200'); - $response->headers = array('content-type'=> 'text/html'); - $this->assertEquals('text/html', $response->get_content_type(), 'Content type should be text/html'); - $response->headers = array('Content-Type'=> 'text/xml'); - $this->assertEquals('text/xml', $response->get_content_type(), 'Content type should be text/xml'); - + $this->assertTrue($response->is_success(), 'Should have handled empty body without causing error'); } } ?> diff --git a/tests/runtests.php b/tests/runtests.php index 82946ff..f20295e 100644 --- a/tests/runtests.php +++ b/tests/runtests.php @@ -17,6 +17,7 @@ require_once MORIARTY_TEST_DIR . 'fieldpredicatemap.test.php'; require_once MORIARTY_TEST_DIR . 'valuepool.test.php'; require_once MORIARTY_TEST_DIR . 'httprequest.test.php'; +require_once MORIARTY_TEST_DIR . 'httpresponse.test.php'; require_once MORIARTY_TEST_DIR . 'credentials.test.php'; require_once MORIARTY_TEST_DIR . 'privategraph.test.php'; require_once MORIARTY_TEST_DIR . 'contentbox.test.php'; @@ -42,6 +43,7 @@ require_once MORIARTY_TEST_DIR . 'datatableresult.test.php'; error_reporting(E_ALL && ~E_STRICT); + function exceptions_error_handler($severity, $message, $filename, $lineno) { if (error_reporting() == 0) { return; @@ -81,6 +83,7 @@ public static function suite() $suite->addTestSuite('CredentialsTest'); $suite->addTestSuite('ValuePoolTest'); $suite->addTestSuite('HttpRequestTest'); + $suite->addTestSuite('HttpResponseTest'); $suite->addTestSuite('PrivateGraphTest'); $suite->addTestSuite('MetaboxTest'); $suite->addTestSuite('ContentboxTest');