Skip to content

Commit abddada

Browse files
ausinicolas-grekas
authored andcommitted
[HttpFoundation] Always return strings from accept headers
1 parent b5a40b7 commit abddada

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,8 @@ public function getLanguages()
16461646

16471647
$languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
16481648
$this->languages = [];
1649-
foreach ($languages as $lang => $acceptHeaderItem) {
1649+
foreach ($languages as $acceptHeaderItem) {
1650+
$lang = $acceptHeaderItem->getValue();
16501651
if (str_contains($lang, '-')) {
16511652
$codes = explode('-', $lang);
16521653
if ('i' === $codes[0]) {
@@ -1684,7 +1685,7 @@ public function getCharsets()
16841685
return $this->charsets;
16851686
}
16861687

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

16901691
/**
@@ -1698,7 +1699,7 @@ public function getEncodings()
16981699
return $this->encodings;
16991700
}
17001701

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

17041705
/**
@@ -1712,7 +1713,7 @@ public function getAcceptableContentTypes()
17121713
return $this->acceptableContentTypes;
17131714
}
17141715

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

17181719
/**

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,20 @@ public function testGetLanguages()
15821582
$this->assertEquals(['zh', 'cherokee'], $request->getLanguages());
15831583
}
15841584

1585+
public function testGetAcceptHeadersReturnString()
1586+
{
1587+
$request = new Request();
1588+
$request->headers->set('Accept', '123');
1589+
$request->headers->set('Accept-Charset', '123');
1590+
$request->headers->set('Accept-Encoding', '123');
1591+
$request->headers->set('Accept-Language', '123');
1592+
1593+
$this->assertSame(['123'], $request->getAcceptableContentTypes());
1594+
$this->assertSame(['123'], $request->getCharsets());
1595+
$this->assertSame(['123'], $request->getEncodings());
1596+
$this->assertSame(['123'], $request->getLanguages());
1597+
}
1598+
15851599
public function testGetRequestFormat()
15861600
{
15871601
$request = new Request();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy