Skip to content

Commit f69fc89

Browse files
authored
Merge pull request #227 from kalessil/master
SCA with Php Inspections (EA Extended)
2 parents ed0fc63 + eec4bea commit f69fc89

6 files changed

Lines changed: 9 additions & 26 deletions

File tree

examples/32-upgrade-chat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
// send anything that is received to the whole channel
5555
$in->on('data', function ($data) use ($username, $chat) {
56-
$data = trim(preg_replace('/[^\w\d \.\,\-\!\?]/u', '', $data));
56+
$data = trim(preg_replace('/[^\w \.\,\-\!\?]/u', '', $data));
5757

5858
$chat->write($username . ': ' . $data . PHP_EOL);
5959
});

src/RequestHeaderParser.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,15 @@ private function parseRequest($headers)
149149
}
150150

151151
// only support HTTP/1.1 and HTTP/1.0 requests
152-
if ($request->getProtocolVersion() !== '1.1' && $request->getProtocolVersion() !== '1.0') {
152+
$protocolVersion = $request->getProtocolVersion();
153+
if ($protocolVersion !== '1.1' && $protocolVersion !== '1.0') {
153154
throw new \InvalidArgumentException('Received request with invalid protocol version', 505);
154155
}
155156

156157
// ensure absolute-form request-target contains a valid URI
157-
if (strpos($request->getRequestTarget(), '://') !== false && substr($request->getRequestTarget(), 0, 1) !== '/') {
158-
$parts = parse_url($request->getRequestTarget());
158+
$requestTarget = $request->getRequestTarget();
159+
if (strpos($requestTarget, '://') !== false && substr($requestTarget, 0, 1) !== '/') {
160+
$parts = parse_url($requestTarget);
159161

160162
// make sure value contains valid host component (IP or hostname), but no fragment
161163
if (!isset($parts['scheme'], $parts['host']) || $parts['scheme'] !== 'http' || isset($parts['fragment'])) {

src/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function handleConnection(ConnectionInterface $conn)
168168
$parser = new RequestHeaderParser($uriLocal, $uriRemote);
169169

170170
$listener = array($parser, 'feed');
171-
$parser->on('headers', function (RequestInterface $request, $bodyBuffer) use ($conn, $listener, $parser, $that) {
171+
$parser->on('headers', function (RequestInterface $request, $bodyBuffer) use ($conn, $listener, $that) {
172172
// parsing request completed => stop feeding parser
173173
$conn->removeListener('data', $listener);
174174

tests/FunctionalServerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public function testClosedStreamFromRequestHandlerWillSendEmptyBody()
443443
$socket = new Socket(0, $loop);
444444
$server->listen($socket);
445445

446-
$result = $connector->connect($socket->getAddress())->then(function (ConnectionInterface $conn) use ($loop) {
446+
$result = $connector->connect($socket->getAddress())->then(function (ConnectionInterface $conn) {
447447
$conn->write("GET / HTTP/1.0\r\n\r\n");
448448

449449
return Stream\buffer($conn);

tests/Middleware/RequestBodyParserMiddlewareTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ function (ServerRequestInterface $request) {
127127
}
128128
);
129129

130-
$this->assertSame(
131-
null,
132-
$parsedRequest->getParsedBody()
133-
);
130+
$this->assertNull($parsedRequest->getParsedBody());
134131
$this->assertSame('{"hello":"world"}', (string)$parsedRequest->getBody());
135132
}
136133

tests/ServerTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,8 +2634,6 @@ function ($data) use (&$buffer) {
26342634
$server->listen($this->socket);
26352635
$this->socket->emit('connection', array($this->connection));
26362636

2637-
$data = "GET / HTTP/1.0\r\n\r\n";
2638-
26392637
$data = $this->createGetRequest();
26402638

26412639
$this->connection->emit('data', array($data));
@@ -2665,8 +2663,6 @@ function ($data) use (&$buffer) {
26652663
$server->listen($this->socket);
26662664
$this->socket->emit('connection', array($this->connection));
26672665

2668-
$data = "GET / HTTP/1.0\r\n\r\n";
2669-
26702666
$data = $this->createGetRequest();
26712667

26722668
$this->connection->emit('data', array($data));
@@ -2698,8 +2694,6 @@ function ($data) use (&$buffer) {
26982694
$server->listen($this->socket);
26992695
$this->socket->emit('connection', array($this->connection));
27002696

2701-
$data = "GET / HTTP/1.0\r\n\r\n";
2702-
27032697
$data = $this->createGetRequest();
27042698

27052699
$this->connection->emit('data', array($data));
@@ -2731,8 +2725,6 @@ function ($data) use (&$buffer) {
27312725
$server->listen($this->socket);
27322726
$this->socket->emit('connection', array($this->connection));
27332727

2734-
$data = "GET / HTTP/1.0\r\n\r\n";
2735-
27362728
$data = $this->createGetRequest();
27372729

27382730
$this->connection->emit('data', array($data));
@@ -2761,8 +2753,6 @@ function ($data) use (&$buffer) {
27612753
$server->listen($this->socket);
27622754
$this->socket->emit('connection', array($this->connection));
27632755

2764-
$data = "GET / HTTP/1.0\r\n\r\n";
2765-
27662756
$data = $this->createGetRequest();
27672757

27682758
$this->connection->emit('data', array($data));
@@ -2795,8 +2785,6 @@ function ($data) use (&$buffer) {
27952785
$server->listen($this->socket);
27962786
$this->socket->emit('connection', array($this->connection));
27972787

2798-
$data = "GET / HTTP/1.0\r\n\r\n";
2799-
28002788
$data = $this->createGetRequest();
28012789

28022790
$this->connection->emit('data', array($data));
@@ -2830,8 +2818,6 @@ function ($data) use (&$buffer) {
28302818
$server->listen($this->socket);
28312819
$this->socket->emit('connection', array($this->connection));
28322820

2833-
$data = "GET / HTTP/1.0\r\n\r\n";
2834-
28352821
$data = $this->createGetRequest();
28362822

28372823
$this->connection->emit('data', array($data));
@@ -2915,8 +2901,6 @@ function ($data) use (&$buffer) {
29152901
$server->listen($this->socket);
29162902
$this->socket->emit('connection', array($this->connection));
29172903

2918-
$data = "GET / HTTP/1.0\r\n\r\n";
2919-
29202904
$data = $this->createGetRequest();
29212905

29222906
$this->connection->emit('data', array($data));

0 commit comments

Comments
 (0)