Skip to content

Commit c8d1ce3

Browse files
committed
Merge branch '3.2'
* 3.2: fixed tests fixed merge Fix minor phpdoc mismatches with the code(detected by phan) [Asset] Starting slash should indicate no basePath wanted [Security] Fix phpdoc logout listener [EventDispatcher] fix getting priorities of listeners during dispatch Add iconv extension to suggested dependencies Fix minor typo in the main README.md Allow Upper Case property names in ObjectNormalizer [EventDispatcher] fix: unwrap listeners for correct info
2 parents 6ff3bff + 6eeae1b commit c8d1ce3

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Encoder/XmlEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ private function appendNode(\DOMNode $parentNode, $data, $nodeName, $key = null)
473473
*/
474474
private function needsCdataWrapping($val)
475475
{
476-
return preg_match('/[<>&]/', $val);
476+
return 0 < preg_match('/[<>&]/', $val);
477477
}
478478

479479
/**

Normalizer/ObjectNormalizer.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ protected function extractAttributes($object, $format = null, array $context = a
6262

6363
if (0 === strpos($name, 'get') || 0 === strpos($name, 'has')) {
6464
// getters and hassers
65-
$attributeName = lcfirst(substr($name, 3));
65+
$attributeName = substr($name, 3);
66+
67+
if (!$reflClass->hasProperty($attributeName)) {
68+
$attributeName = lcfirst($attributeName);
69+
}
6670
} elseif (strpos($name, 'is') === 0) {
6771
// issers
68-
$attributeName = lcfirst(substr($name, 2));
72+
$attributeName = substr($name, 2);
73+
74+
if (!$reflClass->hasProperty($attributeName)) {
75+
$attributeName = lcfirst($attributeName);
76+
}
6977
}
7078

7179
if (null !== $attributeName && $this->isAllowedAttribute($object, $attributeName, $format, $context)) {

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ public function testNormalizeStatic()
509509
$this->assertEquals(array('foo' => 'K'), $this->normalizer->normalize(new ObjectWithStaticPropertiesAndMethods()));
510510
}
511511

512+
public function testNormalizeUpperCaseAttributes()
513+
{
514+
$this->assertEquals(array('Foo' => 'Foo', 'Bar' => 'BarBar'), $this->normalizer->normalize(new ObjectWithUpperCaseAttributeNames()));
515+
}
516+
512517
public function testNormalizeNotSerializableContext()
513518
{
514519
$objectDummy = new ObjectDummy();
@@ -999,3 +1004,14 @@ public function getInner()
9991004
return $this->inner;
10001005
}
10011006
}
1007+
1008+
class ObjectWithUpperCaseAttributeNames
1009+
{
1010+
private $Foo = 'Foo';
1011+
public $Bar = 'BarBar';
1012+
1013+
public function getFoo()
1014+
{
1015+
return $this->Foo;
1016+
}
1017+
}

0 commit comments

Comments
 (0)