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

[PropertyAccess] make cache keys encoding bijective #29332

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
Nov 26, 2018
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
[PropertyAccess] make cache keys encoding bijective
  • Loading branch information
nicolas-grekas committed Nov 26, 2018
commit 4fe566bbc61a4be2cfed171442ae1733ec731a5f
11 changes: 5 additions & 6 deletions 11 src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,14 @@ private function readProperty($zval, $property)
*/
private function getReadAccessInfo($class, $property)
{
$key = false !== strpbrk($key = $class.'..'.$property, '{}()/@:') ? rawurlencode($key) : $key;
$key = str_replace('\\', '.', $class).'..'.$property;

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

if ($this->cacheItemPool) {
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_READ.str_replace('\\', '.', $key));
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_READ.rawurlencode($key));
if ($item->isHit()) {
return $this->readPropertyCache[$key] = $item->get();
}
Expand Down Expand Up @@ -687,14 +687,14 @@ private function writeCollection($zval, $property, $collection, $addMethod, $rem
*/
private function getWriteAccessInfo($class, $property, $value)
{
$key = false !== strpbrk($key = $class.'..'.$property, '{}()/@:') ? rawurlencode($key) : $key;
$key = str_replace('\\', '.', $class).'..'.$property;

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

if ($this->cacheItemPool) {
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_WRITE.str_replace('\\', '.', $key));
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_WRITE.rawurlencode($key));
if ($item->isHit()) {
return $this->writePropertyCache[$key] = $item->get();
}
Expand Down Expand Up @@ -868,8 +868,7 @@ private function getPropertyPath($propertyPath)
}

if ($this->cacheItemPool) {
$key = false !== strpbrk($propertyPath, '{}()/@:') ? rawurlencode($propertyPath) : $propertyPath;
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_PROPERTY_PATH.str_replace('\\', '.', $key));
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_PROPERTY_PATH.rawurlencode($propertyPath));
if ($item->isHit()) {
return $this->propertyPathCache[$propertyPath] = $item->get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,13 @@ public function testAttributeWithSpecialChars()
{
$obj = new \stdClass();
$obj->{'@foo'} = 'bar';
$obj->{'a/b'} = '1';
$obj->{'a%2Fb'} = '2';

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

/**
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.