-
Notifications
You must be signed in to change notification settings - Fork 498
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
CS: don't use assignments in conditions #411
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
} | ||
|
@@ -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) { | ||
Comment on lines
+837
to
+839
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is changing as well because of the stripped cast to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing. |
||
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) { | ||
Comment on lines
+849
to
+851
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is changing as well because of the stripped cast to |
||
return $decoded; | ||
} | ||
} | ||
|
||
return $data; | ||
|
@@ -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; | ||
} | ||
} | ||
|
@@ -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; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code not exactly the same. In the original code, the
&&
operator will cause the result of$decoded = @gzdecode($data)
to be cast as abool
before being compared tofalse
.In the changed code, this casting doesn't happen, and considering we do a strict comparison, it would for example have a different result when
$decoded = @gzdecode($data)
would returnnull
.Now, according to the docs,
gzdecode()
would only ever returnfalse
on failure. But I'm unsure what it would return if you successfully decode a document of zero length. Would it returnnull
then?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the new version is actually more correct, but it would be a BC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basing myself also on the documentation, I would expect it to return an empty string in that case as the standard return type is a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if that would ever make a difference, so I'm not convinced this is a BC-break.
To proof my point: https://3v4l.org/OAoLN