Skip to content
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

[HttpFoundation] Fatal Error Parsing Empty Accept Header #54868

Closed
rezsk opened this issue May 8, 2024 · 0 comments
Closed

[HttpFoundation] Fatal Error Parsing Empty Accept Header #54868

rezsk opened this issue May 8, 2024 · 0 comments

Comments

@rezsk
Copy link

rezsk commented May 8, 2024

Symfony version(s) affected

7.0.7

Description

A fatal error occurs when parsing the Accept header if it only consists of semi-colons.

Fatal error: Uncaught TypeError: Symfony\Component\HttpFoundation\AcceptHeaderItem::__construct(): Argument #1 ($value) must be of type string, null given, called in /Users/reza/Code/http-foundation-bug/vendor/symfony/http-foundation/AcceptHeader.php on line 56 and defined in /Users/reza/Code/http-foundation-bug/vendor/symfony/http-foundation/AcceptHeaderItem.php on line 26

TypeError: Symfony\Component\HttpFoundation\AcceptHeaderItem::__construct(): Argument #1 ($value) must be of type string, null given, called in /Users/reza/Code/http-foundation-bug/vendor/symfony/http-foundation/AcceptHeader.php on line 56 in /Users/reza/Code/http-foundation-bug/vendor/symfony/http-foundation/AcceptHeaderItem.php on line 26

Call Stack:
    0.0001     497448   1. {main}() /Users/reza/Code/http-foundation-bug/src/run.php:0
    0.0015     704056   2. Symfony\Component\HttpFoundation\AcceptHeader::fromString($headerValue = ';;;') /Users/reza/Code/http-foundation-bug/src/run.php:8
    0.0018     739616   3. array_map($callback = class Closure {  }, $array = [0 => []]) /Users/reza/Code/http-foundation-bug/vendor/symfony/http-foundation/AcceptHeader.php:51
    0.0018     739936   4. Symfony\Component\HttpFoundation\AcceptHeader::Symfony\Component\HttpFoundation\{closure:/Users/reza/Code/http-foundation-bug/vendor/symfony/http-foundation/AcceptHeader.php:51-60}($subParts = []) /Users/reza/Code/http-foundation-bug/vendor/symfony/http-foundation/AcceptHeader.php:51
    0.0024     741184   5. Symfony\Component\HttpFoundation\AcceptHeaderItem->__construct($value = NULL, $attributes = []) /Users/reza/Code/http-foundation-bug/vendor/symfony/http-foundation/AcceptHeader.php:56

How to reproduce

<?php

include "../vendor/autoload.php";

use Symfony\Component\HttpFoundation\AcceptHeader;

var_dump(
    AcceptHeader::fromString(";;;")
);

Possible Solution

No response

Additional Context

No response

@rezsk rezsk added the Bug label May 8, 2024
nicolas-grekas added a commit that referenced this issue May 15, 2024
This PR was merged into the 5.4 branch.

Discussion
----------

[HttpFoundation]  filter out empty HTTP header parts

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54868
| License       | MIT

Commits
-------

7d6d8cd filter out empty HTTP header parts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants