Skip to content

Commit

Permalink
fix: make sure parameters are parsed in MediaTypeParser
Browse files Browse the repository at this point in the history
  • Loading branch information
neoncitylights committed Dec 9, 2023
1 parent 3ff4bc7 commit e208cee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/MediaTypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private function collectParameters( string $s, int $length, int &$position ): ar
fn( string $c ) => Utf8Utils::isHttpTokenCodepoint( $c ) )
&& Utf8Utils::onlyContains( $parameterValue,
fn( string $c ) => Utf8Utils::isHttpQuotedStringTokenCodepoint( $c ) )
&& isset( $parameters[$parameterValue] )
&& !isset( $parameters[$parameterName] )
) {
$parameters[$parameterName] = $parameterValue;
}
Expand Down
26 changes: 13 additions & 13 deletions tests/MediaTypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function testValidMediaTypes(
string $validMediaType,
string $expectedType,
string $expectedSubType,
// array $expectedParameters
array $expectedParameters
): void {
$parsedValue = $this->parser->parse( $validMediaType );

$this->assertInstanceOf( MediaType::class, $parsedValue );
$this->assertEquals( $expectedType, $parsedValue->getType() );
$this->assertEquals( $expectedSubType, $parsedValue->getSubType() );
// $this->assertEquals( $expectedParameters, $parsedValue->getParameters() );
$this->assertEquals( $expectedParameters, $parsedValue->getParameters() );
}

/**
Expand All @@ -50,37 +50,37 @@ public function provideValidMediaTypes(): array {
'text/plain',
'text',
'plain',
// [],
[],
],
[
'text/plain;charset=UTF-8',
'text',
'plain',
// [
// 'charset' => 'UTF-8',
// ],
[
'charset' => 'UTF-8',
],
],
[
' text/plain;charset=UTF-8 ',
'text',
'plain',
// [
// 'charset' => 'UTF-8',
// ],
[
'charset' => 'UTF-8',
],
],
[
' text/plain; charset=UTF-8 ',
'text',
'plain',
// [
// 'charset' => 'UTF-8',
// ],
[
'charset' => 'UTF-8',
],
],
[
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application',
'vnd.openxmlformats-officedocument.presentationml.presentation',
// [],
[],
]
];
}
Expand Down

0 comments on commit e208cee

Please sign in to comment.