diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index ea9c746f..573819bb 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -151,14 +151,16 @@ class Smarty_Compiler extends Smarty { // $foo->bar($foo->bar()) // $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar)) $this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')'; - $this->_obj_params_regexp = '\((?:\w+|(?:' + $this->_obj_restricted_param_regexp = '(?:' . $this->_var_regexp . '(?:' . $this->_obj_ext_regexp . '(?:\((?:' . $this->_var_regexp - . '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?)*)(?:\s*,\s*(?:(?:\w+|' - . $this->_var_regexp . '(?:' . $this->_obj_ext_regexp . '(?:\((?:' . $this->_var_regexp - . '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?))))*)?\)'; + . '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?)*)'; + $this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|' + . $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)'; + $this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp + . '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)'; $this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)'; $this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?)'; - + // matches valid modifier syntax: // |foo // |@foo diff --git a/unit_test/test_cases.php b/unit_test/test_cases.php index 4208dc9c..f74facaf 100644 --- a/unit_test/test_cases.php +++ b/unit_test/test_cases.php @@ -3,6 +3,16 @@ require_once './config.php'; require_once SMARTY_DIR . 'Smarty.class.php'; require_once 'PHPUnit.php'; + +class Obj { + var $val = 'val'; + var $arr = array('one' => 'one'); + + function meth($a="a", $b="b") { + return "$a:$b"; + } +} + class SmartyTest extends PHPUnit_TestCase { // contains the object handle of the string class @@ -230,6 +240,22 @@ class SmartyTest extends PHPUnit_TestCase { $this->smarty->assign('foo', 'bar'); $this->assertEquals($this->smarty->fetch('assign_var.tpl'), 'bar'); } + + // test assigning and calling an object + function test_obj_meth() { + $obj = new Obj(); + $this->smarty->assign('obj', $obj); + $this->smarty->assign('foo', 'foo'); + $this->assertEquals( +'foo:2.5 +2.5:foo +2.5:b +val:foo +foo:val +foo:foo +one:2 +foo:foo:b', $this->smarty->fetch('assign_obj.tpl')); + } /* CONFIG FILE TESTS */