mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 03:57:21 +00:00
Fix wrong array index
This commit is contained in:
@@ -116,9 +116,8 @@ class ArrayExpression extends AbstractExpression
|
||||
->subcompile($pair['key'])
|
||||
->raw(' => ')
|
||||
;
|
||||
} else {
|
||||
++$nextIndex;
|
||||
}
|
||||
++$nextIndex;
|
||||
|
||||
$compiler->subcompile($pair['value']);
|
||||
}
|
||||
|
||||
@@ -55,11 +55,25 @@ Twig supports array notation
|
||||
{% set trad = {194:'ABC',141:'DEF',100:'GHI',170:'JKL',110:'MNO',111:'PQR'} %}
|
||||
{% set trad2 = {'194':'ABC','141':'DEF','100':'GHI','170':'JKL','110':'MNO','111':'PQR'} %}
|
||||
{{ trad == trad2 ? 'OK' : 'KO' }}
|
||||
|
||||
{# indexes are kept #}
|
||||
{{ { 1: "first", 0: "second" } == { '1': "first", '0': "second" } ? 'OK' : 'KO' }}
|
||||
{{ { 1: "first", 0: "second" } == indices_1 ? 'OK' : 'KO' }}
|
||||
{{ { 1: "first", 'foo': "second", 2: "third" } == { '1': "first", 'foo': "second", '2': "third" } ? 'OK' : 'KO' }}
|
||||
{{ { 1: "first", 'foo': "second", 2: "third" } == indices_2 ? 'OK' : 'KO' }}
|
||||
--DATA--
|
||||
$objectStorage = new SplObjectStorage();
|
||||
$object = new stdClass();
|
||||
$objectStorage[$object] = 'foo';
|
||||
return ['bar' => 'bar', 'foo' => ['bar' => 'bar'], 'array_access' => new \ArrayObject(['a' => 'b']), 'object_storage' => $objectStorage, 'object' => $object]
|
||||
return [
|
||||
'bar' => 'bar',
|
||||
'foo' => ['bar' => 'bar'],
|
||||
'array_access' => new \ArrayObject(['a' => 'b']),
|
||||
'object_storage' => $objectStorage,
|
||||
'object' => $object,
|
||||
'indices_1' => [ 1 => 'first', 0 => 'second' ],
|
||||
'indices_2' => [ 1 => 'first', 'foo' => 'second', 2 => 'third' ],
|
||||
]
|
||||
--EXPECT--
|
||||
1,2
|
||||
foo,bar
|
||||
@@ -90,9 +104,21 @@ ok
|
||||
ok
|
||||
ok
|
||||
|
||||
OK
|
||||
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
--DATA--
|
||||
return ['bar' => 'bar', 'foo' => ['bar' => 'bar'], 'array_access' => new \ArrayObject(['a' => 'b']), 'object' => new stdClass()]
|
||||
return [
|
||||
'bar' => 'bar',
|
||||
'foo' => ['bar' => 'bar'],
|
||||
'array_access' => new \ArrayObject(['a' => 'b']),
|
||||
'object' => new stdClass(),
|
||||
'indices_1' => [ 1 => 'first', 0 => 'second' ],
|
||||
'indices_2' => [ 1 => 'first', 'foo' => 'second', 2 => 'third' ],
|
||||
]
|
||||
--CONFIG--
|
||||
return ['strict_variables' => false]
|
||||
--EXPECT--
|
||||
@@ -126,3 +152,8 @@ ok
|
||||
ok
|
||||
|
||||
OK
|
||||
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
|
||||
Reference in New Issue
Block a user