Skip to content

Commit

Permalink
Replace PHP_EOL with \r\n
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Oct 29, 2015
1 parent 7cb4f9f commit 27f7b3c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Processor/MultipartUploadProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function getPart(Request $request)
throw new UploadProcessorException(sprintf('An empty content found'));
}

$headerLimitation = strpos($content, PHP_EOL.PHP_EOL) + 1;
$headerLimitation = strpos($content, "\r\n\r\n") + 1;
if ($headerLimitation == -1) {
throw new UploadProcessorException('Unable to determine headers limit');
}
Expand All @@ -142,7 +142,7 @@ protected function getPart(Request $request)
$body = substr($content, $headerLimitation);
$body = trim($body);

foreach (explode(PHP_EOL, $headersContent) as $header) {
foreach (explode("\r\n", $headersContent) as $header) {
$parts = explode(':', $header);
if (count($parts) != 2) {
continue;
Expand Down Expand Up @@ -170,7 +170,7 @@ protected function getRequestPart(Request $request, $boundary)
{
$contentHandler = $this->getRequestContentHandler($request);

$delimiter = '--'.$boundary.PHP_EOL;
$delimiter = '--'.$boundary."\r\n";
$endDelimiter = '--'.$boundary.'--';
$boundaryCount = 0;
$content = '';
Expand All @@ -192,7 +192,7 @@ protected function getRequestPart(Request $request, $boundary)
$boundaryCount++;
} elseif ($line == $delimiter) {
break;
} elseif ($line == $endDelimiter || $line == $endDelimiter.PHP_EOL) {
} elseif ($line == $endDelimiter || $line == $endDelimiter."\r\n") {
break;
}

Expand Down
6 changes: 3 additions & 3 deletions Request/RequestContentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ public function gets()
return $line;
}

$next = strpos($content, PHP_EOL, $this->cursor);
$next = strpos($content, "\r\n", $this->cursor);
$eof = $next < 0 || $next === false;

if ($eof) {
$line = substr($content, $this->cursor);
} else {
$length = $next - $this->cursor + strlen(PHP_EOL);
$length = $next - $this->cursor + strlen("\r\n");
$line = substr($content, $this->cursor, $length);
}

$this->cursor = $eof ? -1 : $next + strlen(PHP_EOL);
$this->cursor = $eof ? -1 : $next + strlen("\r\n");

return $line;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Processor/MultipartUploadProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ protected function createMultipartRequest($jsonData, $binaryContent)

protected function createMultipartContent($boundary, $jsonData, $binaryContent)
{
$content = '--'.$boundary.PHP_EOL.'Content-Type: application/json; charset=UTF-8'.PHP_EOL.PHP_EOL.$jsonData.PHP_EOL.PHP_EOL;
$content .= '--'.$boundary.PHP_EOL.'Content-Type: image/gif'.PHP_EOL.PHP_EOL.$binaryContent.PHP_EOL.PHP_EOL;
$content = '--'.$boundary."\r\n".'Content-Type: application/json; charset=UTF-8'."\r\n\r\n".$jsonData."\r\n\r\n";
$content .= '--'.$boundary."\r\n".'Content-Type: image/gif'."\r\n\r\n".$binaryContent."\r\n\r\n";
$content .= '--'.$boundary.'--';

return $content;
Expand Down
18 changes: 9 additions & 9 deletions Tests/Upload/MultipartUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function testWithoutContent()
$queryParameters = array('name' => 'test');

$boundary = uniqid();
$content = '--'.$boundary.PHP_EOL.'Content-Type: application/json; charset=UTF-8'.PHP_EOL.PHP_EOL.json_encode($queryParameters).PHP_EOL.PHP_EOL;
$content = '--'.$boundary."\r\n".'Content-Type: application/json; charset=UTF-8'."\r\n\r\n".json_encode($queryParameters)."\r\n\r\n";
$content .= '--'.$boundary.'--';

$client->request('POST', '/upload?uploadType=multipart', array(), array(), array(
Expand All @@ -26,8 +26,8 @@ public function testWithoutHeaders()

$boundary = uniqid();
$image = $this->getResource($client, 'apple.gif');
$content = '--'.$boundary.PHP_EOL.'Content-Type: image/gif'.PHP_EOL.PHP_EOL.$image.PHP_EOL.PHP_EOL;
$content .= '--'.$boundary.PHP_EOL.'Content-Type: application/json; charset=UTF-8'.PHP_EOL.PHP_EOL.json_encode($queryParameters).PHP_EOL.PHP_EOL;
$content = '--'.$boundary."\r\n".'Content-Type: image/gif'."\r\n\r\n".$image."\r\n\r\n";
$content .= '--'.$boundary."\r\n".'Content-Type: application/json; charset=UTF-8'."\r\n\r\n".json_encode($queryParameters)."\r\n\r\n";
$content .= '--'.$boundary.'--';

$client->request('POST', '/upload?uploadType=multipart', array(), array(), array(), $content);
Expand All @@ -41,8 +41,8 @@ public function testWithoutBoundary()

$boundary = uniqid();
$image = $this->getResource($client, 'apple.gif');
$content = '--'.$boundary.PHP_EOL.'Content-Type: image/gif'.PHP_EOL.PHP_EOL.$image.PHP_EOL.PHP_EOL;
$content .= '--'.$boundary.PHP_EOL.'Content-Type: application/json; charset=UTF-8'.PHP_EOL.PHP_EOL.json_encode($queryParameters).PHP_EOL.PHP_EOL;
$content = '--'.$boundary."\r\n".'Content-Type: image/gif'."\r\n\r\n".$image."\r\n\r\n";
$content .= '--'.$boundary."\r\n".'Content-Type: application/json; charset=UTF-8'."\r\n\r\n".json_encode($queryParameters)."\r\n\r\n";
$content .= '--'.$boundary.'--';

$client->request('POST', '/upload?uploadType=multipart', array(), array(), array(
Expand All @@ -59,8 +59,8 @@ public function testBinaryBeforeMeta()

$boundary = uniqid();
$image = $this->getResource($client, 'apple.gif');
$content = '--'.$boundary.PHP_EOL.'Content-Type: image/gif'.PHP_EOL.PHP_EOL.$image.PHP_EOL.PHP_EOL;
$content .= '--'.$boundary.PHP_EOL.'Content-Type: application/json; charset=UTF-8'.PHP_EOL.PHP_EOL.json_encode($queryParameters).PHP_EOL.PHP_EOL;
$content = '--'.$boundary."\r\n".'Content-Type: image/gif'."\r\n\r\n".$image."\r\n\r\n";
$content .= '--'.$boundary."\r\n".'Content-Type: application/json; charset=UTF-8'."\r\n\r\n".json_encode($queryParameters)."\r\n\r\n";
$content .= '--'.$boundary.'--';

$client->request('POST', '/upload?uploadType=multipart', array(), array(), array(
Expand All @@ -77,8 +77,8 @@ public function testMultipartUpload()

$boundary = uniqid();
$image = $this->getResource($client, 'apple.gif');
$content = '--'.$boundary.PHP_EOL.'Content-Type: application/json; charset=UTF-8'.PHP_EOL.PHP_EOL.json_encode($queryParameters).PHP_EOL.PHP_EOL;
$content .= '--'.$boundary.PHP_EOL.'Content-Type: image/gif'.PHP_EOL.PHP_EOL.$image.PHP_EOL.PHP_EOL;
$content = '--'.$boundary."\r\n".'Content-Type: application/json; charset=UTF-8'."\r\n\r\n".json_encode($queryParameters)."\r\n\r\n";
$content .= '--'.$boundary."\r\n".'Content-Type: image/gif'."\r\n\r\n".$image."\r\n\r\n";
$content .= '--'.$boundary.'--';

$client->request('POST', '/upload?uploadType=multipart', array(), array(), array(
Expand Down

0 comments on commit 27f7b3c

Please sign in to comment.