Pastakhov has uploaded a new change for review.
https://gerrit.wikimedia.org/r/97709
Change subject: fix for double arrays in encapsed string
......................................................................
fix for double arrays in encapsed string
* fix for usage right operators in param of functions
(testRun_echo_array_encapsed_14)
* add tag <br /> in error messages (ExceptionFoxway)
Time: 510 ms, Memory: 25.00Mb
OK (507 tests, 513 assertions)
Change-Id: I2058a16ff5ad7ce3ffdeafbfcc1d255a88cdb2e3
---
M includes/Compiler.php
M includes/ExceptionFoxway.php
M tests/phpunit/includes/RuntimeTest.php
3 files changed, 73 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Foxway
refs/changes/09/97709/1
diff --git a/includes/Compiler.php b/includes/Compiler.php
index 5222217..28a5bd8 100644
--- a/includes/Compiler.php
+++ b/includes/Compiler.php
@@ -654,21 +654,25 @@
$stack =
array_merge( $stack, $rightOperators );
$rightOperators
= array();
}
+ $lastVariable =
&$needParams[0];
+
$lastVariable[FOXWAY_STACK_ARRAY_INDEX][] = &$lastValue;
$stackEncapsed =
array_pop( $memEncapsed );
if ( $stackEncapsed !==
false ) {
$needOperator =
false;
+ if(
!is_string($tokens[$index+1]) || $tokens[$index+1][0] != '[' ) {
+ unset(
$lastVariable, $lastValue );
+ }
+ } else {
+ $lastValue =
&$lastVariable;
+ if (
$parentFlags & FOXWAY_NEED_RESTORE_RIGHT_OPERATORS ) { // Need restore right
operators
+
$rightOperators = array_pop( $memOperators );
+ }
+ if (
$parentFlags & FOXWAY_NEED_RESTORE_OPERATOR ) {
+
$operator = array_pop( $memOperators );
+ }
}
- $lastVariable =
&$needParams[0];
-
$lastVariable[FOXWAY_STACK_ARRAY_INDEX][] = &$lastValue;
- $lastValue =
&$lastVariable;
-
array_shift($needParams);
- if( $parentFlags &
FOXWAY_NEED_RESTORE_RIGHT_OPERATORS ) { // Need restore right operators
- $rightOperators
= array_pop( $memOperators );
- }
- if( $parentFlags &
FOXWAY_NEED_RESTORE_OPERATOR ) {
- $operator =
array_pop( $memOperators );
- }
- $parentFlags =
array_pop($parentheses);
+ array_shift(
$needParams );
+ $parentFlags =
array_pop( $parentheses );
// if (
!is_string($tokens[$index+1]) || $tokens[$index+1][0] != '[' ) { // leave
$lastVariable for array index only
// unset(
$lastVariable );
// }
@@ -682,6 +686,15 @@
case ')':
$parentLevel--;
if( $parentFlags &
FOXWAY_EXPECT_PARENTHES_CLOSE == 0 ) { throw new ExceptionFoxway($id,
FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); }
+
+ if ( $rightOperators ) {
+
$rightOperators[0][FOXWAY_STACK_PARAM_2] = &$lastValue[FOXWAY_STACK_RESULT];
+ $k =
array_keys( $rightOperators );
+ $lk =
array_pop( $k );
+ $lastValue =
&$rightOperators[$lk];
+ $stack =
array_merge( $stack, $rightOperators );
+ $rightOperators
= array();
+ }
if ( $parentFlags &
FOXWAY_THIS_IS_FUNCTION ) {
if (
isset($lastVariable) ) {
if (
$parentFlags & FOXWAY_NEED_ADD_VARIABLE_IN_STACK ) {
diff --git a/includes/ExceptionFoxway.php b/includes/ExceptionFoxway.php
index 7421243..00ab8be 100644
--- a/includes/ExceptionFoxway.php
+++ b/includes/ExceptionFoxway.php
@@ -87,7 +87,7 @@
break;
}
//return "$message in $place on line $line\n";
- return \Html::element( 'span', array('class'=>'error'),
"$message in $place on line $line" );
+ return \Html::element( 'span', array('class'=>'error'),
"$message in $place on line $line" ) . '<br />';
}
}
diff --git a/tests/phpunit/includes/RuntimeTest.php
b/tests/phpunit/includes/RuntimeTest.php
index 4d8a103..e1469e3 100644
--- a/tests/phpunit/includes/RuntimeTest.php
+++ b/tests/phpunit/includes/RuntimeTest.php
@@ -1664,6 +1664,54 @@
array('-=FOO=-', 'BAR')
);
}
+ public function testRun_echo_array_encapsed_7() {
+ $this->assertEquals(
+ Runtime::runSource('$foo=(array)5; echo
"*$foo[0]*|*$foo[0]*";'),
+ array('*5*|*5*')
+ );
+ }
+ public function testRun_echo_array_encapsed_8() {
+ $this->assertEquals(
+ Runtime::runSource('$foo=(array)5; echo
"*$foo[0]$foo[0]*";'),
+ array('*55*')
+ );
+ }
+ public function testRun_echo_array_encapsed_9() {
+ $this->assertEquals(
+ Runtime::runSource('$foo=(array)5; echo
"*{$foo[0]}*|*{$foo[0]}*";'),
+ array('*5*|*5*')
+ );
+ }
+ public function testRun_echo_array_encapsed_10() {
+ $this->assertEquals(
+ Runtime::runSource('$foo=(array)5; echo
"*{$foo[0]}{$foo[0]}*";'),
+ array('*55*')
+ );
+ }
+ public function testRun_echo_array_encapsed_11() {
+ $this->assertEquals(
+ Runtime::runSource('$foo=array(3,array(5));
echo "*$foo[0]*|*{$foo[1][0]}*";'),
+ array('*3*|*5*')
+ );
+ }
+ public function testRun_echo_array_encapsed_12() {
+ $this->assertEquals(
+ Runtime::runSource('$foo=array(3,array(5));
echo "*$foo[0]{$foo[1][0]}*";'),
+ array('*35*')
+ );
+ }
+ public function testRun_echo_array_encapsed_13() {
+ $this->assertEquals(
+ Runtime::runSource('$foo=array(3,array(5));
echo "*{$foo[0]}{$foo[1][0]}*";'),
+ array('*35*')
+ );
+ }
+ public function testRun_echo_array_encapsed_14() {
+ $this->assertEquals(
+ Runtime::runSource('$foo=array(3,(array)5);
echo "*{$foo[0]}{$foo[1][0]}*";'),
+ array('*35*')
+ );
+ }
public function testRun_echo_array_right_1() {
$this->assertEquals(
Runtime::runSource('$foo=array("123"); echo
(bool)$foo[0];'),
--
To view, visit https://gerrit.wikimedia.org/r/97709
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2058a16ff5ad7ce3ffdeafbfcc1d255a88cdb2e3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Foxway
Gerrit-Branch: develop
Gerrit-Owner: Pastakhov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits