8000 [HttpFoundation] Always return strings from accept headers by ausi · Pull Request #47530 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Always return strings from accept headers #47530

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

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Symfony/Component/HttpFoundation/Request.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,8 @@ public function getLanguages()

$languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
$this->languages = [];
foreach ($languages as $lang => $acceptHeaderItem) {
foreach ($languages as $acceptHeaderItem) {
$lang = $acceptHeaderItem->getValue();
if (str_contains($lang, '-')) {
$codes = explode('-', $lang);
if ('i' === $codes[0]) {
Expand Down Expand Up @@ -1684,7 +1685,7 @@ public function getCharsets()
return $this->charsets;
}

return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all());
return $this->charsets = array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all()));
}

/**
Expand All @@ -1698,7 +1699,7 @@ public function getEncodings()
return $this->encodings;
}

return $this->encodings = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all());
return $this->encodings = array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all()));
}

/**
Expand All @@ -1712,7 +1713,7 @@ public function getAcceptableContentTypes()
return $this->acceptableContentTypes;
}

return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all());
return $this->acceptableContentTypes = array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all()));
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,20 @@ public function testGetLanguages()
$this->assertEquals(['zh', 'cherokee'], $request->getLanguages());
}

public function testGetAcceptHeadersReturnString()
{
$request = new Request();
$request->headers->set('Accept', '123');
$request->headers->set('Accept-Charset', '123');
$request->headers->set('Accept-Encoding', '123');
$request->headers->set('Accept-Language', '123');

$this->assertSame(['123'], $request->getAcceptableContentTypes());
$this->assertSame(['123'], $request->getCharsets());
$this->assertSame(['123'], $request->getEncodings());
$this->assertSame(['123'], $request->getLanguages());
}

public function testGetRequestFormat()
{
$request = new Request();
Expand Down
0