[WebLink] Escape double quotes in attributes values
This commit is contained in:
parent
08c789c97b
commit
7946be2b95
@ -39,14 +39,14 @@ final class HttpHeaderSerializer
|
||||
foreach ($link->getAttributes() as $key => $value) {
|
||||
if (\is_array($value)) {
|
||||
foreach ($value as $v) {
|
||||
$attributesParts[] = sprintf('%s="%s"', $key, $v);
|
||||
$attributesParts[] = sprintf('%s="%s"', $key, preg_replace('/(?<!\\\\)"/', '\"', $v));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!\is_bool($value)) {
|
||||
$attributesParts[] = sprintf('%s="%s"', $key, $value);
|
||||
$attributesParts[] = sprintf('%s="%s"', $key, preg_replace('/(?<!\\\\)"/', '\"', $value));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -44,4 +44,12 @@ class HttpHeaderSerializerTest extends TestCase
|
||||
{
|
||||
$this->assertNull($this->serializer->serialize([]));
|
||||
}
|
||||
|
||||
public function testSerializeDoubleQuotesInAttributeValue()
|
||||
{
|
||||
$this->assertSame('</foo>; rel="alternate"; title="\"escape me\" \"already escaped\" \"\"\""', $this->serializer->serialize([
|
||||
(new Link('alternate', '/foo'))
|
||||
->withAttribute('title', '"escape me" \"already escaped\" ""\"'),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user