Changeset 929

Show
Ignore:
Timestamp:
05/07/08 01:01:41 (2 months ago)
Author:
laurentj
Message:

ticket #573: bad support of round brackets in 'if' statements in jTpl

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0.x/lib/jelix/tpl/jTplCompiler.class.php

    r742 r929  
    44* @subpackage  jtpl 
    55* @author      Laurent Jouanneau 
    6 * @contributor Mathaud Loic (version standalone), Dominique Papin 
    7 * @copyright   2005-2007 Laurent Jouanneau 
     6* @contributor Mathaud Loic (standalone version), Dominique Papin 
     7* @copyright   2005-2008 Laurent Jouanneau 
    88* @copyright   2006 Mathaud Loic, 2007 Dominique Papin 
    99* @link        http://www.jelix.org 
     
    308308                break; 
    309309            case 'foreach': 
    310                 $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!')).'):'; 
     310                $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!','(')).'):'; 
    311311                array_push($this->_blockStack,'foreach'); 
    312312                break; 
     
    316316                break; 
    317317            case 'for': 
    318                 $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array()) .'):'; 
     318                $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array('(')) .'):'; 
    319319                array_push($this->_blockStack,'for'); 
    320320                break; 
     
    470470                } elseif ($inLocale && ($tok=='.' || $tok =='~') ) { 
    471471                    $locale.=$tok; 
    472                 } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok !='!')) { 
     472                } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok != '!' && $tok != '(')) { 
    473473                    $this->doError2('errors.tpl.tag.character.invalid', $this->_currentTag, $tok); 
    474474                } elseif ($tok =='(') { 
  • branches/1.0.x/lib/jelix/tpl/jTplCompiler.class.php

    r742 r929  
    44* @subpackage  jtpl 
    55* @author      Laurent Jouanneau 
    6 * @contributor Mathaud Loic (version standalone), Dominique Papin 
    7 * @copyright   2005-2007 Laurent Jouanneau 
     6* @contributor Mathaud Loic (standalone version), Dominique Papin 
     7* @copyright   2005-2008 Laurent Jouanneau 
    88* @copyright   2006 Mathaud Loic, 2007 Dominique Papin 
    99* @link        http://www.jelix.org 
     
    308308                break; 
    309309            case 'foreach': 
    310                 $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!')).'):'; 
     310                $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!','(')).'):'; 
    311311                array_push($this->_blockStack,'foreach'); 
    312312                break; 
     
    316316                break; 
    317317            case 'for': 
    318                 $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array()) .'):'; 
     318                $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array('(')) .'):'; 
    319319                array_push($this->_blockStack,'for'); 
    320320                break; 
     
    470470                } elseif ($inLocale && ($tok=='.' || $tok =='~') ) { 
    471471                    $locale.=$tok; 
    472                 } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok !='!')) { 
     472                } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok != '!' && $tok != '(')) { 
    473473                    $this->doError2('errors.tpl.tag.character.invalid', $this->_currentTag, $tok); 
    474474                } elseif ($tok =='(') { 
  • branches/1.0.x/lib/jelix/tpl/jTplCompiler.class.php

    r742 r929  
    44* @subpackage  jtpl 
    55* @author      Laurent Jouanneau 
    6 * @contributor Mathaud Loic (version standalone), Dominique Papin 
    7 * @copyright   2005-2007 Laurent Jouanneau 
     6* @contributor Mathaud Loic (standalone version), Dominique Papin 
     7* @copyright   2005-2008 Laurent Jouanneau 
    88* @copyright   2006 Mathaud Loic, 2007 Dominique Papin 
    99* @link        http://www.jelix.org 
     
    308308                break; 
    309309            case 'foreach': 
    310                 $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!')).'):'; 
     310                $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!','(')).'):'; 
    311311                array_push($this->_blockStack,'foreach'); 
    312312                break; 
     
    316316                break; 
    317317            case 'for': 
    318                 $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array()) .'):'; 
     318                $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array('(')) .'):'; 
    319319                array_push($this->_blockStack,'for'); 
    320320                break; 
     
    470470                } elseif ($inLocale && ($tok=='.' || $tok =='~') ) { 
    471471                    $locale.=$tok; 
    472                 } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok !='!')) { 
     472                } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok != '!' && $tok != '(')) { 
    473473                    $this->doError2('errors.tpl.tag.character.invalid', $this->_currentTag, $tok); 
    474474                } elseif ($tok =='(') { 
  • branches/1.0.x/lib/jelix/tpl/jTplCompiler.class.php

    r742 r929  
    44* @subpackage  jtpl 
    55* @author      Laurent Jouanneau 
    6 * @contributor Mathaud Loic (version standalone), Dominique Papin 
    7 * @copyright   2005-2007 Laurent Jouanneau 
     6* @contributor Mathaud Loic (standalone version), Dominique Papin 
     7* @copyright   2005-2008 Laurent Jouanneau 
    88* @copyright   2006 Mathaud Loic, 2007 Dominique Papin 
    99* @link        http://www.jelix.org 
     
    308308                break; 
    309309            case 'foreach': 
    310                 $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!')).'):'; 
     310                $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!','(')).'):'; 
    311311                array_push($this->_blockStack,'foreach'); 
    312312                break; 
     
    316316                break; 
    317317            case 'for': 
    318                 $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array()) .'):'; 
     318                $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array('(')) .'):'; 
    319319                array_push($this->_blockStack,'for'); 
    320320                break; 
     
    470470                } elseif ($inLocale && ($tok=='.' || $tok =='~') ) { 
    471471                    $locale.=$tok; 
    472                 } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok !='!')) { 
     472                } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok != '!' && $tok != '(')) { 
    473473                    $this->doError2('errors.tpl.tag.character.invalid', $this->_currentTag, $tok); 
    474474                } elseif ($tok =='(') { 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jtpl.compiler.html_cli.php

    r742 r929  
    8787        '<p>ok</p>', 
    8888        ), 
    89  
     8911=>array( 
     90        '<p>ok{if $foo} {/if}</p>', 
     91        '<p>ok<?php if($t->_vars[\'foo\']):?> <?php endif;?></p>', 
     92        ), 
     9312=>array( 
     94        '<p>ok{if ($foo)} {/if}</p>', 
     95        '<p>ok<?php if(($t->_vars[\'foo\'])):?> <?php endif;?></p>', 
     96        ), 
     9713=>array( 
     98        '<p>ok{while ($foo)} {/while}</p>', 
     99        '<p>ok<?php while(($t->_vars[\'foo\'])):?> <?php endwhile;?></p>', 
     100        ), 
     10114=>array( 
     102        '<p>ok{while $foo} {/while}</p>', 
     103        '<p>ok<?php while($t->_vars[\'foo\']):?> <?php endwhile;?></p>', 
     104        ), 
     10515=>array( 
     106        '<p>ok{jurl ($foo)}</p>', 
     107        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\']));?></p>', 
     108        ), 
     10916=>array( 
     110        '<p>ok{jurl ($foo,$params)}</p>', 
     111        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\'],$t->_vars[\'params\']));?></p>', 
     112        ), 
     11317=>array( 
     114        '<p>ok{$foo.($truc.$bbb)}</p>', 
     115        '<p>ok<?php echo $t->_vars[\'foo\'].($t->_vars[\'truc\'].$t->_vars[\'bbb\']); ?></p>', 
     116        ), 
     11718=>array( 
     118        '<p>ok{if ($foo || $bar) && $baz} {/if}</p>', 
     119        '<p>ok<?php if(($t->_vars[\'foo\'] || $t->_vars[\'bar\']) && $t->_vars[\'baz\']):?> <?php endif;?></p>', 
     120        ), 
    90121    ); 
    91122 
    92123    function testCompileContent() { 
    93124        $compil = new testJtplContentCompiler(); 
     125        $compil->outputType = 'html'; 
    94126        $compil->trusted = true; 
    95127 
     
    129161    function testCompilePlugins() { 
    130162        $compil = new testJtplContentCompiler(); 
     163        $compil->outputType = 'html'; 
    131164        $compil->trusted = true; 
    132165 
     
    141174        } 
    142175    } 
    143      
     176 
    144177    protected $tplerrors = array( 
    145          0=>array('{if}', 
     178         0=>array('{if $foo}', 
    146179                  'jelix~errors.tpl.tag.block.end.missing',array('if',null) ), 
    147          1=>array('{ifuserconnected} {if}  {/if} ', 
     180         1=>array('{ifuserconnected} {if $foo}  {/if} ', 
    148181                  'jelix~errors.tpl.tag.block.end.missing',array('ifuserconnected',null) ), 
     182         2=>array('{foreach ($t=>$a)} A {/foreach}', 
     183                  'jelix~errors.tpl.tag.character.invalid',array('foreach ($t=>$a)', '(', NULL) ), 
     184         3=>array('{for ($i=0;$i<$p;$i++)} A {/for}', 
     185                  'jelix~errors.tpl.tag.character.invalid',array('for ($i=0;$i<$p;$i++)','(',null) ), 
     186         4=>array('{form ($foo,$params)} aa {/form}', 
     187                  'jelix~errors.tplplugin.block.bad.argument.number',array('form','2-6',null) ), 
     188         5=>array('{($aaa)}', 
     189                  'jelix~errors.tpl.tag.syntax.invalid',array('($aaa)',null) ), 
    149190         ); 
    150      
     191 
    151192    function testCompileErrors() { 
    152         $compil = new testJtplContentCompiler(); 
    153         $compil->trusted = true; 
    154193 
    155194        foreach($this->tplerrors as $k=>$t){ 
     195            $compil = new testJtplContentCompiler(); 
     196            $compil->outputType = 'html'; 
     197            $compil->trusted = true; 
    156198            try{ 
    157199                $compil->compileContent2($t[0]); 
    158200                $this->fail("Test '$k', exception didn't happen"); 
    159201            }catch(jException $e){ 
    160                 $this->assertEqual($e->getLocaleKey(), $t[1]); 
    161                 $this->assertEqualOrDiff($e->getLocaleParameters(), $t[2]); 
     202                $this->assertEqual($e->getLocaleKey(), $t[1], "Test '$k': %s  (local parameters: ".var_export($e->getLocaleParameters(), true).")"); 
     203                $this->assertEqualOrDiff($e->getLocaleParameters(), $t[2], "Test '$k': %s"); 
    162204            }catch(Exception $e){ 
    163205                $this->fail("Test '$k', Unknown Exception: ".$e->getMessage()); 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jtpl.compiler.html_cli.php

    r742 r929  
    8787        '<p>ok</p>', 
    8888        ), 
    89  
     8911=>array( 
     90        '<p>ok{if $foo} {/if}</p>', 
     91        '<p>ok<?php if($t->_vars[\'foo\']):?> <?php endif;?></p>', 
     92        ), 
     9312=>array( 
     94        '<p>ok{if ($foo)} {/if}</p>', 
     95        '<p>ok<?php if(($t->_vars[\'foo\'])):?> <?php endif;?></p>', 
     96        ), 
     9713=>array( 
     98        '<p>ok{while ($foo)} {/while}</p>', 
     99        '<p>ok<?php while(($t->_vars[\'foo\'])):?> <?php endwhile;?></p>', 
     100        ), 
     10114=>array( 
     102        '<p>ok{while $foo} {/while}</p>', 
     103        '<p>ok<?php while($t->_vars[\'foo\']):?> <?php endwhile;?></p>', 
     104        ), 
     10515=>array( 
     106        '<p>ok{jurl ($foo)}</p>', 
     107        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\']));?></p>', 
     108        ), 
     10916=>array( 
     110        '<p>ok{jurl ($foo,$params)}</p>', 
     111        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\'],$t->_vars[\'params\']));?></p>', 
     112        ), 
     11317=>array( 
     114        '<p>ok{$foo.($truc.$bbb)}</p>', 
     115        '<p>ok<?php echo $t->_vars[\'foo\'].($t->_vars[\'truc\'].$t->_vars[\'bbb\']); ?></p>', 
     116        ), 
     11718=>array( 
     118        '<p>ok{if ($foo || $bar) && $baz} {/if}</p>', 
     119        '<p>ok<?php if(($t->_vars[\'foo\'] || $t->_vars[\'bar\']) && $t->_vars[\'baz\']):?> <?php endif;?></p>', 
     120        ), 
    90121    ); 
    91122 
    92123    function testCompileContent() { 
    93124        $compil = new testJtplContentCompiler(); 
     125        $compil->outputType = 'html'; 
    94126        $compil->trusted = true; 
    95127 
     
    129161    function testCompilePlugins() { 
    130162        $compil = new testJtplContentCompiler(); 
     163        $compil->outputType = 'html'; 
    131164        $compil->trusted = true; 
    132165 
     
    141174        } 
    142175    } 
    143      
     176 
    144177    protected $tplerrors = array( 
    145          0=>array('{if}', 
     178         0=>array('{if $foo}', 
    146179                  'jelix~errors.tpl.tag.block.end.missing',array('if',null) ), 
    147          1=>array('{ifuserconnected} {if}  {/if} ', 
     180         1=>array('{ifuserconnected} {if $foo}  {/if} ', 
    148181                  'jelix~errors.tpl.tag.block.end.missing',array('ifuserconnected',null) ), 
     182         2=>array('{foreach ($t=>$a)} A {/foreach}', 
     183                  'jelix~errors.tpl.tag.character.invalid',array('foreach ($t=>$a)', '(', NULL) ), 
     184         3=>array('{for ($i=0;$i<$p;$i++)} A {/for}', 
     185                  'jelix~errors.tpl.tag.character.invalid',array('for ($i=0;$i<$p;$i++)','(',null) ), 
     186         4=>array('{form ($foo,$params)} aa {/form}', 
     187                  'jelix~errors.tplplugin.block.bad.argument.number',array('form','2-6',null) ), 
     188         5=>array('{($aaa)}', 
     189                  'jelix~errors.tpl.tag.syntax.invalid',array('($aaa)',null) ), 
    149190         ); 
    150      
     191 
    151192    function testCompileErrors() { 
    152         $compil = new testJtplContentCompiler(); 
    153         $compil->trusted = true; 
    154193 
    155194        foreach($this->tplerrors as $k=>$t){ 
     195            $compil = new testJtplContentCompiler(); 
     196            $compil->outputType = 'html'; 
     197            $compil->trusted = true; 
    156198            try{ 
    157199                $compil->compileContent2($t[0]); 
    158200                $this->fail("Test '$k', exception didn't happen"); 
    159201            }catch(jException $e){ 
    160                 $this->assertEqual($e->getLocaleKey(), $t[1]); 
    161                 $this->assertEqualOrDiff($e->getLocaleParameters(), $t[2]); 
     202                $this->assertEqual($e->getLocaleKey(), $t[1], "Test '$k': %s  (local parameters: ".var_export($e->getLocaleParameters(), true).")"); 
     203                $this->assertEqualOrDiff($e->getLocaleParameters(), $t[2], "Test '$k': %s"); 
    162204            }catch(Exception $e){ 
    163205                $this->fail("Test '$k', Unknown Exception: ".$e->getMessage()); 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jtpl.compiler.html_cli.php

    r742 r929  
    8787        '<p>ok</p>', 
    8888        ), 
    89  
     8911=>array( 
     90        '<p>ok{if $foo} {/if}</p>', 
     91        '<p>ok<?php if($t->_vars[\'foo\']):?> <?php endif;?></p>', 
     92        ), 
     9312=>array( 
     94        '<p>ok{if ($foo)} {/if}</p>', 
     95        '<p>ok<?php if(($t->_vars[\'foo\'])):?> <?php endif;?></p>', 
     96        ), 
     9713=>array( 
     98        '<p>ok{while ($foo)} {/while}</p>', 
     99        '<p>ok<?php while(($t->_vars[\'foo\'])):?> <?php endwhile;?></p>', 
     100        ), 
     10114=>array( 
     102        '<p>ok{while $foo} {/while}</p>', 
     103        '<p>ok<?php while($t->_vars[\'foo\']):?> <?php endwhile;?></p>', 
     104        ), 
     10515=>array( 
     106        '<p>ok{jurl ($foo)}</p>', 
     107        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\']));?></p>', 
     108        ), 
     10916=>array( 
     110        '<p>ok{jurl ($foo,$params)}</p>', 
     111        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\'],$t->_vars[\'params\']));?></p>', 
     112        ), 
     11317=>array( 
     114        '<p>ok{$foo.($truc.$bbb)}</p>', 
     115        '<p>ok<?php echo $t->_vars[\'foo\'].($t->_vars[\'truc\'].$t->_vars[\'bbb\']); ?></p>', 
     116        ), 
     11718=>array( 
     118        '<p>ok{if ($foo || $bar) && $baz} {/if}</p>', 
     119        '<p>ok<?php if(($t->_vars[\'foo\'] || $t->_vars[\'bar\']) && $t->_vars[\'baz\']):?> <?php endif;?></p>', 
     120        ), 
    90121    ); 
    91122 
    92123    function testCompileContent() { 
    93124        $compil = new testJtplContentCompiler(); 
     125        $compil->outputType = 'html'; 
    94126        $compil->trusted = true; 
    95127 
     
    129161    function testCompilePlugins() { 
    130162        $compil = new testJtplContentCompiler(); 
     163        $compil->outputType = 'html'; 
    131164        $compil->trusted = true; 
    132165 
     
    141174        } 
    142175    } 
    143      
     176 
    144177    protected $tplerrors = array( 
    145          0=>array('{if}', 
     178         0=>array('{if $foo}', 
    146179                  'jelix~errors.tpl.tag.block.end.missing',array('if',null) ), 
    147          1=>array('{ifuserconnected} {if}  {/if} ', 
     180         1=>array('{ifuserconnected} {if $foo}  {/if} ', 
    148181                  'jelix~errors.tpl.tag.block.end.missing',array('ifuserconnected',null) ), 
     182         2=>array('{foreach ($t=>$a)} A {/foreach}', 
     183                  'jelix~errors.tpl.tag.character.invalid',array('foreach ($t=>$a)', '(', NULL) ), 
     184         3=>array('{for ($i=0;$i<$p;$i++)} A {/for}', 
     185                  'jelix~errors.tpl.tag.character.invalid',array('for ($i=0;$i<$p;$i++)','(',null) ), 
     186         4=>array('{form ($foo,$params)} aa {/form}', 
     187                  'jelix~errors.tplplugin.block.bad.argument.number',array('form','2-6',null) ), 
     188         5=>array('{($aaa)}', 
     189                  'jelix~errors.tpl.tag.syntax.invalid',array('($aaa)',null) ), 
    149190         ); 
    150      
     191 
    151192    function testCompileErrors() { 
    152         $compil = new testJtplContentCompiler(); 
    153         $compil->trusted = true; 
    154193 
    155194        foreach($this->tplerrors as $k=>$t){ 
     195            $compil = new testJtplContentCompiler(); 
     196            $compil->outputType = 'html'; 
     197            $compil->trusted = true; 
    156198            try{ 
    157199                $compil->compileContent2($t[0]); 
    158200                $this->fail("Test '$k', exception didn't happen"); 
    159201            }catch(jException $e){ 
    160                 $this->assertEqual($e->getLocaleKey(), $t[1]); 
    161                 $this->assertEqualOrDiff($e->getLocaleParameters(), $t[2]); 
     202                $this->assertEqual($e->getLocaleKey(), $t[1], "Test '$k': %s  (local parameters: ".var_export($e->getLocaleParameters(), true).")"); 
     203                $this->assertEqualOrDiff($e->getLocaleParameters(), $t[2], "Test '$k': %s"); 
    162204            }catch(Exception $e){ 
    163205                $this->fail("Test '$k', Unknown Exception: ".$e->getMessage()); 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jtpl.compiler.html_cli.php

    r742 r929  
    8787        '<p>ok</p>', 
    8888        ), 
    89  
     8911=>array( 
     90        '<p>ok{if $foo} {/if}</p>', 
     91        '<p>ok<?php if($t->_vars[\'foo\']):?> <?php endif;?></p>', 
     92        ), 
     9312=>array( 
     94        '<p>ok{if ($foo)} {/if}</p>', 
     95        '<p>ok<?php if(($t->_vars[\'foo\'])):?> <?php endif;?></p>', 
     96        ), 
     9713=>array( 
     98        '<p>ok{while ($foo)} {/while}</p>', 
     99        '<p>ok<?php while(($t->_vars[\'foo\'])):?> <?php endwhile;?></p>', 
     100        ), 
     10114=>array( 
     102        '<p>ok{while $foo} {/while}</p>', 
     103        '<p>ok<?php while($t->_vars[\'foo\']):?> <?php endwhile;?></p>', 
     104        ), 
     10515=>array( 
     106        '<p>ok{jurl ($foo)}</p>', 
     107        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\']));?></p>', 
     108        ), 
     10916=>array( 
     110        '<p>ok{jurl ($foo,$params)}</p>', 
     111        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\'],$t->_vars[\'params\']));?></p>', 
     112        ), 
     11317=>array( 
     114        '<p>ok{$foo.($truc.$bbb)}</p>', 
     115        '<p>ok<?php echo $t->_vars[\'foo\'].($t->_vars[\'truc\'].$t->_vars[\'bbb\']); ?></p>', 
     116        ), 
     11718=>array( 
     118        '<p>ok{if ($foo || $bar) && $baz} {/if}</p>', 
     119        '<p>ok<?php if(($t->_vars[\'foo\'] || $t->_vars[\'bar\']) && $t->_vars[\'baz\']):?> <?php endif;?></p>', 
     120        ), 
    90121    ); 
    91122 
    92123    function testCompileContent() { 
    93124        $compil = new testJtplContentCompiler(); 
     125        $compil->outputType = 'html'; 
    94126        $compil->trusted = true; 
    95127 
     
    129161    function testCompilePlugins() { 
    130162        $compil = new testJtplContentCompiler(); 
     163        $compil->outputType = 'html'; 
    131164        $compil->trusted = true; 
    132165 
     
    141174        } 
    142175    } 
    143      
     176 
    144177    protected $tplerrors = array( 
    145          0=>array('{if}', 
     178         0=>array('{if $foo}', 
    146179                  'jelix~errors.tpl.tag.block.end.missing',array('if',null) ), 
    147          1=>array('{ifuserconnected} {if}  {/if} ', 
     180         1=>array('{ifuserconnected} {if $foo}  {/if} ', 
    148181                  'jelix~errors.tpl.tag.block.end.missing',array('ifuserconnected',null) ), 
     182         2=>array('{foreach ($t=>$a)} A {/foreach}', 
     183                  'jelix~errors.tpl.tag.character.invalid',array('foreach ($t=>$a)', '(', NULL) ), 
     184         3=>array('{for ($i=0;$i<$p;$i++)} A {/for}', 
     185                  'jelix~errors.tpl.tag.character.invalid',array('for ($i=0;$i<$p;$i++)','(',null) ), 
     186         4=>array('{form ($foo,$params)} aa {/form}', 
     187                  'jelix~errors.tplplugin.block.bad.argument.number',array('form','2-6',null) ), 
     188         5=>array('{($aaa)}', 
     189                  'jelix~errors.tpl.tag.syntax.invalid',array('($aaa)',null) ), 
    149190         ); 
    150      
     191 
    151192    function testCompileErrors() { 
    152         $compil = new testJtplContentCompiler(); 
    153         $compil->trusted = true; 
    154193 
    155194        foreach($this->tplerrors as $k=>$t){ 
     195            $compil = new testJtplContentCompiler(); 
     196            $compil->outputType = 'html'; 
     197            $compil->trusted = true; 
    156198            try{ 
    157199                $compil->compileContent2($t[0]); 
    158200                $this->fail("Test '$k', exception didn't happen"); 
    159201            }catch(jException $e){ 
    160                 $this->assertEqual($e->getLocaleKey(), $t[1]); 
    161                 $this->assertEqualOrDiff($e->getLocaleParameters(), $t[2]); 
     202                $this->assertEqual($e->getLocaleKey(), $t[1], "Test '$k': %s  (local parameters: ".var_export($e->getLocaleParameters(), true).")"); 
     203                $this->assertEqualOrDiff($e->getLocaleParameters(), $t[2], "Test '$k': %s"); 
    162204            }catch(Exception $e){ 
    163205                $this->fail("Test '$k', Unknown Exception: ".$e->getMessage()); 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jtpl.expressions_parsing.html_cli.php

    r571 r929  
    162162        '@@'=>array('jelix~errors.tpl.tag.locale.invalid',array('','')), 
    163163        '[$aa/234]'=>array('jelix~errors.tpl.tag.character.invalid',array('','[','')), 
    164         '($aa/234)'=>array('jelix~errors.tpl.tag.character.invalid',array('','(','')), 
    165164        '$b+($aa/234'=>array('jelix~errors.tpl.tag.bracket.error',array('','')), 
    166165        '$b+(($aa/234)'=>array('jelix~errors.tpl.tag.bracket.error',array('','')), 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jtpl.expressions_parsing.html_cli.php

    r571 r929  
    162162        '@@'=>array('jelix~errors.tpl.tag.locale.invalid',array('','')), 
    163163        '[$aa/234]'=>array('jelix~errors.tpl.tag.character.invalid',array('','[','')), 
    164         '($aa/234)'=>array('jelix~errors.tpl.tag.character.invalid',array('','(','')), 
    165164        '$b+($aa/234'=>array('jelix~errors.tpl.tag.bracket.error',array('','')), 
    166165        '$b+(($aa/234)'=>array('jelix~errors.tpl.tag.bracket.error',array('','')), 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jtpl.expressions_parsing.html_cli.php

    r571 r929  
    162162        '@@'=>array('jelix~errors.tpl.tag.locale.invalid',array('','')), 
    163163        '[$aa/234]'=>array('jelix~errors.tpl.tag.character.invalid',array('','[','')), 
    164         '($aa/234)'=>array('jelix~errors.tpl.tag.character.invalid',array('','(','')), 
    165164        '$b+($aa/234'=>array('jelix~errors.tpl.tag.bracket.error',array('','')), 
    166165        '$b+(($aa/234)'=>array('jelix~errors.tpl.tag.bracket.error',array('','')), 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/jtpl.expressions_parsing.html_cli.php

    r571 r929  
    162162        '@@'=>array('jelix~errors.tpl.tag.locale.invalid',array('','')), 
    163163        '[$aa/234]'=>array('jelix~errors.tpl.tag.character.invalid',array('','[','')), 
    164         '($aa/234)'=>array('jelix~errors.tpl.tag.character.invalid',array('','(','')), 
    165164        '$b+($aa/234'=>array('jelix~errors.tpl.tag.bracket.error',array('','')), 
    166165        '$b+(($aa/234)'=>array('jelix~errors.tpl.tag.bracket.error',array('','')), 
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r892 r929  
    44* @subpackage  jtpl 
    55* @author      Laurent Jouanneau 
    6 * @contributor Mathaud Loic (version standalone), Dominique Papin 
    7 * @copyright   2005-2007 Laurent Jouanneau 
     6* @contributor Mathaud Loic (standalone version), Dominique Papin 
     7* @copyright   2005-2008 Laurent Jouanneau 
    88* @copyright   2006 Mathaud Loic, 2007 Dominique Papin 
    99* @link        http://www.jelix.org 
     
    306306                break; 
    307307            case 'foreach': 
    308                 $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!')).'):'; 
     308                $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!','(')).'):'; 
    309309                array_push($this->_blockStack,'foreach'); 
    310310                break; 
     
    314314                break; 
    315315            case 'for': 
    316                 $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array()) .'):'; 
     316                $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array('(')) .'):'; 
    317317                array_push($this->_blockStack,'for'); 
    318318                break; 
     
    470470                } elseif ($inLocale && ($tok=='.' || $tok =='~') ) { 
    471471                    $locale.=$tok; 
    472                 } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok !='!')) { 
     472                } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok != '!' && $tok != '(')) { 
    473473                    $this->doError2('errors.tpl.tag.character.invalid', $this->_currentTag, $tok); 
    474474                } elseif ($tok =='(') { 
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r892 r929  
    44* @subpackage  jtpl 
    55* @author      Laurent Jouanneau 
    6 * @contributor Mathaud Loic (version standalone), Dominique Papin 
    7 * @copyright   2005-2007 Laurent Jouanneau 
     6* @contributor Mathaud Loic (standalone version), Dominique Papin 
     7* @copyright   2005-2008 Laurent Jouanneau 
    88* @copyright   2006 Mathaud Loic, 2007 Dominique Papin 
    99* @link        http://www.jelix.org 
     
    306306                break; 
    307307            case 'foreach': 
    308                 $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!')).'):'; 
     308                $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!','(')).'):'; 
    309309                array_push($this->_blockStack,'foreach'); 
    310310                break; 
     
    314314                break; 
    315315            case 'for': 
    316                 $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array()) .'):'; 
     316                $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array('(')) .'):'; 
    317317                array_push($this->_blockStack,'for'); 
    318318                break; 
     
    470470                } elseif ($inLocale && ($tok=='.' || $tok =='~') ) { 
    471471                    $locale.=$tok; 
    472                 } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok !='!')) { 
     472                } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok != '!' && $tok != '(')) { 
    473473                    $this->doError2('errors.tpl.tag.character.invalid', $this->_currentTag, $tok); 
    474474                } elseif ($tok =='(') { 
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r892 r929  
    44* @subpackage  jtpl 
    55* @author      Laurent Jouanneau 
    6 * @contributor Mathaud Loic (version standalone), Dominique Papin 
    7 * @copyright   2005-2007 Laurent Jouanneau 
     6* @contributor Mathaud Loic (standalone version), Dominique Papin 
     7* @copyright   2005-2008 Laurent Jouanneau 
    88* @copyright   2006 Mathaud Loic, 2007 Dominique Papin 
    99* @link        http://www.jelix.org 
     
    306306                break; 
    307307            case 'foreach': 
    308                 $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!')).'):'; 
     308                $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!','(')).'):'; 
    309309                array_push($this->_blockStack,'foreach'); 
    310310                break; 
     
    314314                break; 
    315315            case 'for': 
    316                 $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array()) .'):'; 
     316                $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array('(')) .'):'; 
    317317                array_push($this->_blockStack,'for'); 
    318318                break; 
     
    470470                } elseif ($inLocale && ($tok=='.' || $tok =='~') ) { 
    471471                    $locale.=$tok; 
    472                 } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok !='!')) { 
     472                } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok != '!' && $tok != '(')) { 
    473473                    $this->doError2('errors.tpl.tag.character.invalid', $this->_currentTag, $tok); 
    474474                } elseif ($tok =='(') { 
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r892 r929  
    44* @subpackage  jtpl 
    55* @author      Laurent Jouanneau 
    6 * @contributor Mathaud Loic (version standalone), Dominique Papin 
    7 * @copyright   2005-2007 Laurent Jouanneau 
     6* @contributor Mathaud Loic (standalone version), Dominique Papin 
     7* @copyright   2005-2008 Laurent Jouanneau 
    88* @copyright   2006 Mathaud Loic, 2007 Dominique Papin 
    99* @link        http://www.jelix.org 
     
    306306                break; 
    307307            case 'foreach': 
    308                 $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!')).'):'; 
     308                $res = 'foreach('.$this->_parseFinal($args,$this->_allowedInForeach, array(';','!','(')).'):'; 
    309309                array_push($this->_blockStack,'foreach'); 
    310310                break; 
     
    314314                break; 
    315315            case 'for': 
    316                 $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array()) .'):'; 
     316                $res = 'for('. $this->_parseFinal($args, $this->_allowedInExpr, array('(')) .'):'; 
    317317                array_push($this->_blockStack,'for'); 
    318318                break; 
     
    470470                } elseif ($inLocale && ($tok=='.' || $tok =='~') ) { 
    471471                    $locale.=$tok; 
    472                 } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok !='!')) { 
     472                } elseif ($inLocale || in_array($tok,$exceptchar) || ($first && $tok != '!' && $tok != '(')) { 
    473473                    $this->doError2('errors.tpl.tag.character.invalid', $this->_currentTag, $tok); 
    474474                } elseif ($tok =='(') { 
  • trunk/testapp/modules/jelix_tests/tests/jtpl.compiler.html_cli.php

    r815 r929  
    8787        '<p>ok</p>', 
    8888        ), 
    89  
     8911=>array( 
     90        '<p>ok{if $foo} {/if}</p>', 
     91        '<p>ok<?php if($t->_vars[\'foo\']):?> <?php endif;?></p>', 
     92        ), 
     9312=>array( 
     94        '<p>ok{if ($foo)} {/if}</p>', 
     95        '<p>ok<?php if(($t->_vars[\'foo\'])):?> <?php endif;?></p>', 
     96        ), 
     9713=>array( 
     98        '<p>ok{while ($foo)} {/while}</p>', 
     99        '<p>ok<?php while(($t->_vars[\'foo\'])):?> <?php endwhile;?></p>', 
     100        ), 
     10114=>array( 
     102        '<p>ok{while $foo} {/while}</p>', 
     103        '<p>ok<?php while($t->_vars[\'foo\']):?> <?php endwhile;?></p>', 
     104        ), 
     10515=>array( 
     106        '<p>ok{jurl ($foo)}</p>', 
     107        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\']));?></p>', 
     108        ), 
     10916=>array( 
     110        '<p>ok{jurl ($foo,$params)}</p>', 
     111        '<p>ok<?php jtpl_function_html_jurl( $t,($t->_vars[\'foo\'],$t->_vars[\'params\']));?></p>', 
     112        ), 
     11317=>array( 
     114        '<p>ok{$foo.($truc.$bbb)}</p>', 
     115        '<p>ok<?php echo $t->_vars[\'foo\'].($t->_vars[\'truc\'].$t->_vars[\'bbb\']); ?></p>', 
     116        ), 
     11718=>array( 
     118        '<p>ok{if ($foo || $bar) && $baz} {/if}</p>', 
     119        '<p>ok<?php if(($t->_vars[\'foo\'] || $t->_vars[\'bar\']) && $t->_vars[\'baz\']):?> <?php endif;?></p>', 
     120        ), 
    90121    ); 
    91122 
    92123    function testCompileContent() { 
    93124        $compil = new testJtplContentCompiler(); 
     125        $compil->outputType = 'html'; 
    94126        $compil->trusted = true; 
    95127 
     
    143175    function testCompilePlugins() { 
    144176        $compil = new testJtplContentCompiler(); 
     177        $compil->outputType = 'html'; 
    145178        $compil->trusted = true; 
    146179 
     
    157190 
    158191    protected $tplerrors = array( 
    159          0=>array('{if}', 
     192         0=>array('{if $foo}', 
    160193                  'jelix~errors.tpl.tag.block.end.missing',array('if',null) ), 
    161          1=>array('{ifuserconnected} {if}  {/if} ', 
     194         1=>array('{ifuserconnected} {if $foo}  {/if} ', 
    162195      &