8000 [PropertyAccessor] fix encoding of cache keys · symfony/symfony@4568a0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 4568a0c

Browse files
[PropertyAccessor] fix encoding of cache keys
1 parent 7f310b4 commit 4568a0c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ private function readProperty($zval, $property)
508508
*/
509509
private function getReadAccessInfo($class, $property)
510510
{
511-
$key = (false !== strpos($class, '@') ? rawurlencode($class) : $class).'..'.$property;
511+
$key = false !== strpbrk($key = $class.'..'.$property, '{}()/@:') ? rawurlencode($key) : $key;
512512

513513
if (isset($this->readPropertyCache[$key])) {
514514
return $this->readPropertyCache[$key];
@@ -687,7 +687,7 @@ private function writeCollection($zval, $property, $collection, $addMethod, $rem
687687
*/
688688
private function getWriteAccessInfo($class, $property, $value)
689689
{
690-
$key = (false !== strpos($class, '@') ? rawurlencode($class) : $class).'..'.$property;
690+
$key = false !== strpbrk($key = $class.'..'.$property, '{}()/@:') ? rawurlencode($key) : $key;
691691

692692
if (isset($this->writePropertyCache[$key])) {
693693
return $this->writePropertyCache[$key];
@@ -868,7 +868,8 @@ private function getPropertyPath($propertyPath)
868868
}
869869

870870
if ($this->cacheItemPool) {
871-
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_PROPERTY_PATH.$propertyPath);
871+
$key = false !== strpbrk($propertyPath, '{}()/@:') ? rawurlencode($propertyPath) : $propertyPath;
872+
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_PROPERTY_PATH.str_replace('\\', '.', $key));
872873
if ($item->isHit()) {
873874
return $this->propertyPathCache[$propertyPath] = $item->get();
874875
}

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,15 @@ public function testCacheReadAccess()
582582
$this->assertEquals('baz', $propertyAccessor->getValue($obj, 'publicGetSetter'));
583583
}
584584

585+
public function testAttributeWithSpecialChars()
586+
{
587+
$obj = new \stdClass();
588+
$obj->{'@foo'} = 'bar';
589+
590+
$propertyAccessor = new PropertyAccessor(false, false, new ArrayAdapter());
591+
$this->assertSame('bar', $propertyAccessor->getValue($obj, '@foo'));
592+
}
593+
585594
/**
586595
* @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidArgumentException
587596
* @expectedExceptionMessage Expected argument of type "Countable", "string" given

0 commit comments

Comments
 (0)
0