Skip to content

Commit 0042f72

Browse files
matej21dg
authored andcommitted
Decoder: fixed entity value conversion in the entity chain
1 parent 1887e7b commit 0042f72

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

src/Neon/Decoder.php

+20-17
Original file line numberDiff line numberDiff line change
@@ -231,37 +231,40 @@ private function parse($indent, $result = NULL, $key = NULL, $hasKey = FALSE)
231231
}
232232
}
233233

234-
} elseif ($hasValue) { // Value
235-
if ($value instanceof Entity) { // Entity chaining
236-
if ($value->value !== Neon::CHAIN) {
237-
$value = new Entity(Neon::CHAIN, array($value));
238-
}
239-
$value->attributes[] = new Entity($t);
240-
} else {
241-
$this->error();
242-
}
243234
} else { // Value
244235
static $consts = array(
245236
'true' => TRUE, 'True' => TRUE, 'TRUE' => TRUE, 'yes' => TRUE, 'Yes' => TRUE, 'YES' => TRUE, 'on' => TRUE, 'On' => TRUE, 'ON' => TRUE,
246237
'false' => FALSE, 'False' => FALSE, 'FALSE' => FALSE, 'no' => FALSE, 'No' => FALSE, 'NO' => FALSE, 'off' => FALSE, 'Off' => FALSE, 'OFF' => FALSE,
247238
'null' => 0, 'Null' => 0, 'NULL' => 0,
248239
);
249240
if ($t[0] === '"') {
250-
$value = preg_replace_callback('#\\\\(?:ud[89ab][0-9a-f]{2}\\\\ud[c-f][0-9a-f]{2}|u[0-9a-f]{4}|x[0-9a-f]{2}|.)#i', array($this, 'cbString'), substr($t, 1, -1));
241+
$converted = preg_replace_callback('#\\\\(?:ud[89ab][0-9a-f]{2}\\\\ud[c-f][0-9a-f]{2}|u[0-9a-f]{4}|x[0-9a-f]{2}|.)#i', array($this, 'cbString'), substr($t, 1, -1));
251242
} elseif ($t[0] === "'") {
252-
$value = substr($t, 1, -1);
243+
$converted = substr($t, 1, -1);
253244
} elseif (isset($consts[$t]) && (!isset($tokens[$n + 1][0]) || ($tokens[$n + 1][0] !== ':' && $tokens[$n + 1][0] !== '='))) {
254-
$value = $consts[$t] === 0 ? NULL : $consts[$t];
245+
$converted = $consts[$t] === 0 ? NULL : $consts[$t];
255246
} elseif (is_numeric($t)) {
256-
$value = $t * 1;
247+
$converted = $t * 1;
257248
} elseif (preg_match('#0x[0-9a-fA-F]+\z#A', $t)) {
258-
$value = hexdec($t);
249+
$converted = hexdec($t);
259250
} elseif (preg_match('#\d\d\d\d-\d\d?-\d\d?(?:(?:[Tt]| +)\d\d?:\d\d:\d\d(?:\.\d*)? *(?:Z|[-+]\d\d?(?::\d\d)?)?)?\z#A', $t)) {
260-
$value = new \DateTime($t);
251+
$converted = new \DateTime($t);
261252
} else { // literal
262-
$value = $t;
253+
$converted = $t;
254+
}
255+
if ($hasValue) {
256+
if ($value instanceof Entity) { // Entity chaining
257+
if ($value->value !== Neon::CHAIN) {
258+
$value = new Entity(Neon::CHAIN, array($value));
259+
}
260+
$value->attributes[] = new Entity($converted);
261+
} else {
262+
$this->error();
263+
}
264+
} else {
265+
$value = $converted;
266+
$hasValue = TRUE;
263267
}
264-
$hasValue = TRUE;
265268
}
266269
}
267270

tests/Neon/Decoder.inline.array.phpt

+8
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ Assert::equal(
9595
)),
9696
Neon::decode('first(a, b)second(1, 2)')
9797
);
98+
99+
Assert::equal(
100+
new Entity(Neon::CHAIN, array(
101+
new Entity(1, array()),
102+
new Entity(2, array()),
103+
)),
104+
Neon::decode('1() 2()')
105+
);

0 commit comments

Comments
 (0)