Skip to content

Commit

Permalink
Fix parsing if last parameter contains '&'
Browse files Browse the repository at this point in the history
Fixes #6.
  • Loading branch information
kelunik committed Jan 27, 2019
1 parent 8bdb211 commit 2d8a3ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BufferingParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function parseBody(string $body, string $boundary = null): Form
$fields[$field][] = $value;
}

if (\strpos($value ?? "", "&") !== false) {
if (\strpos($pair[1] ?? "", "&") !== false) {
throw new ParseException("Maximum number of variables exceeded");
}

Expand Down
22 changes: 22 additions & 0 deletions src/BufferingParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Amp\Http\Server\FormParser;

use Amp\Http\Server\Driver\Client;
use Amp\Http\Server\Request;
use function Amp\Promise\wait;
use League\Uri\Http;
use PHPUnit\Framework\TestCase;

class BufferingParserTest extends TestCase
{
public function testIssue6()
{
$body = "foobar=" . \urlencode("&");
$request = new Request($this->createMock(Client::class), 'GET', Http::createFromString('/'), [], $body);
$form = wait((new BufferingParser)->parseForm($request));

$this->assertSame('&', $form->getValue('foobar'));
}

}

0 comments on commit 2d8a3ed

Please sign in to comment.