Skip to content

modify empty judgment #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OSS/Core/OssUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static function validateOptions($options)
*/
public static function validateContent($content)
{
if (empty($content)) {
if (!isset($content) || $content === "") {
throw new OssException("http body content is invalid");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OSS/Result/AclResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AclResult extends Result
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
if (empty($content)) {
if (!isset($content) || $content === "") {
throw new OssException("body is null");
}
$xml = simplexml_load_string($content);
Expand Down
2 changes: 1 addition & 1 deletion src/OSS/Result/BodyResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class BodyResult extends Result
*/
protected function parseDataFromResponse()
{
return empty($this->rawResponse->body) ? "" : $this->rawResponse->body;
return isset($this->rawResponse->body) && $this->rawResponse->body !== "" ? $this->rawResponse->body :"";
}
}
5 changes: 2 additions & 3 deletions src/OSS/Result/GetBucketInfoResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ class GetBucketInfoResult extends Result
{
/**
* Parse data from response
*
* @return string
* @return BucketInfo
* @throws OssException
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
if (empty($content)) {
if (!isset($content) || $content === "") {
throw new OssException("body is null");
}
$xml = simplexml_load_string($content);
Expand Down
8 changes: 3 additions & 5 deletions src/OSS/Result/GetLocationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ class GetLocationResult extends Result

/**
* Parse data from response
*
* @return string
* @return false|\SimpleXMLElement|string|null
* @throws OssException
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
if (empty($content)) {
if (!isset($content) || $content === "") {
throw new OssException("body is null");
}
$xml = simplexml_load_string($content);
return $xml;
return simplexml_load_string($content);
}
}
4 changes: 2 additions & 2 deletions src/OSS/Result/GetStorageCapacityResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class GetStorageCapacityResult extends Result
/**
* Parse data from response
*
* @return string
* @return int
* @throws OssException
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
if (empty($content)) {
if (!isset($content) || $content === "") {
throw new OssException("body is null");
}
$xml = simplexml_load_string($content);
Expand Down
15 changes: 15 additions & 0 deletions tests/OSS/Tests/BodyResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ public function testParseValid200()
$result = new BodyResult($response);
$this->assertTrue($result->isOK());
$this->assertEquals($result->getData(), "hi");

$response = new ResponseCore(array(), false, 200);
$result = new BodyResult($response);
$this->assertTrue($result->isOK());
$this->assertEquals($result->getData(), false);

$response = new ResponseCore(array(), 0, 200);
$result = new BodyResult($response);
$this->assertTrue($result->isOK());
$this->assertEquals($result->getData(), 0);

$response = new ResponseCore(array(), "false", 200);
$result = new BodyResult($response);
$this->assertTrue($result->isOK());
$this->assertEquals($result->getData(), "false");
}

public function testParseInvalid404()
Expand Down