Skip to content

Commit

Permalink
Merge pull request #411 from rmccue/feature/cs-no-assignments-in-cond…
Browse files Browse the repository at this point in the history
…ition

CS: don't use assignments in conditions
  • Loading branch information
schlessera authored Oct 24, 2020
2 parents f9c45bf + 4382870 commit 3dd8c19
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions library/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,8 @@ protected static function parse_response($headers, $url, $req_headers, $req_data
$return->url = $url;

if (!$options['filename']) {
if (($pos = strpos($headers, "\r\n\r\n")) === false) {
$pos = strpos($headers, "\r\n\r\n");
if ($pos === false) {
// Crap!
throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator');
}
Expand Down Expand Up @@ -826,17 +827,30 @@ public static function decompress($data) {
return $data;
}

if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) {
return $decoded;
if (function_exists('gzdecode')) {
$decoded = @gzdecode($data);
if ($decoded !== false) {
return $decoded;
}
}
elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) {
return $decoded;

if (function_exists('gzinflate')) {
$decoded = @gzinflate($data);
if ($decoded !== false) {
return $decoded;
}
}
elseif (($decoded = self::compatible_gzinflate($data)) !== false) {

$decoded = self::compatible_gzinflate($data);
if ($decoded !== false) {
return $decoded;
}
elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) {
return $decoded;

if (function_exists('gzuncompress')) {
$decoded = @gzuncompress($data);
if ($decoded !== false) {
return $decoded;
}
}

return $data;
Expand Down Expand Up @@ -910,7 +924,8 @@ public static function compatible_gzinflate($gzData) {
}

if ($huffman_encoded) {
if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
$decompressed = @gzinflate(substr($gzData, 2));
if (false !== $decompressed) {
return $decompressed;
}
}
Expand All @@ -937,20 +952,23 @@ public static function compatible_gzinflate($gzData) {
// Determine the first byte of data, based on the above ZIP header
// offsets:
$first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4)));
if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) {
$decompressed = @gzinflate(substr($gzData, 30 + $first_file_start));
if (false !== $decompressed) {
return $decompressed;
}
return false;
}

// Finally fall back to straight gzinflate
if (false !== ($decompressed = @gzinflate($gzData))) {
$decompressed = @gzinflate($gzData);
if (false !== $decompressed) {
return $decompressed;
}

// Fallback for all above failing, not expected, but included for
// debugging and preventing regressions and to track stats
if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
$decompressed = @gzinflate(substr($gzData, 2));
if (false !== $decompressed) {
return $decompressed;
}

Expand Down

0 comments on commit 3dd8c19

Please sign in to comment.