Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4fe566b

Browse filesBrowse files
[PropertyAccess] make cache keys encoding bijective
1 parent 0878006 commit 4fe566b
Copy full SHA for 4fe566b

File tree

Expand file treeCollapse file tree

2 files changed

+9
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-6
lines changed

‎src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/PropertyAccessor.php
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,14 +508,14 @@ private function readProperty($zval, $property)
508508
*/
509509
private function getReadAccessInfo($class, $property)
510510
{
511-
$key = false !== strpbrk($key = $class.'..'.$property, '{}()/@:') ? rawurlencode($key) : $key;
511+
$key = str_replace('\\', '.', $class).'..'.$property;
512512

513513
if (isset($this->readPropertyCache[$key])) {
514514
return $this->readPropertyCache[$key];
515515
}
516516

517517
if ($this->cacheItemPool) {
518-
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_READ.str_replace('\\', '.', $key));
518+
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_READ.rawurlencode($key));
519519
if ($item->isHit()) {
520520
return $this->readPropertyCache[$key] = $item->get();
521521
}
@@ -687,14 +687,14 @@ private function writeCollection($zval, $property, $collection, $addMethod, $rem
687687
*/
688688
private function getWriteAccessInfo($class, $property, $value)
689689
{
690-
$key = false !== strpbrk($key = $class.'..'.$property, '{}()/@:') ? rawurlencode($key) : $key;
690+
$key = str_replace('\\', '.', $class).'..'.$property;
691691

692692
if (isset($this->writePropertyCache[$key])) {
693693
return $this->writePropertyCache[$key];
694694
}
695695

696696
if ($this->cacheItemPool) {
697-
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_WRITE.str_replace('\\', '.', $key));
697+
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_WRITE.rawurlencode($key));
698698
if ($item->isHit()) {
699699
return $this->writePropertyCache[$key] = $item->get();
700700
}
@@ -868,8 +868,7 @@ private function getPropertyPath($propertyPath)
868868
}
869869

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,13 @@ public function testAttributeWithSpecialChars()
586586
{
587587
$obj = new \stdClass();
588588
$obj->{'@foo'} = 'bar';
589+
$obj->{'a/b'} = '1';
590+
$obj->{'a%2Fb'} = '2';
589591

590592
$propertyAccessor = new PropertyAccessor(false, false, new ArrayAdapter());
591593
$this->assertSame('bar', $propertyAccessor->getValue($obj, '@foo'));
594+
$this->assertSame('1', $propertyAccessor->getValue($obj, 'a/b'));
595+
$this->assertSame('2', $propertyAccessor->getValue($obj, 'a%2Fb'));
592596
}
593597

594598
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.