BUGFIX: Empty if blocks are allowed (were hacky way of doing negation, now replaced by not)

This commit is contained in:
Hamish Friedlander 2011-02-21 16:19:10 +13:00
parent a34df1cb1f
commit 20ba97f8ff
3 changed files with 14 additions and 24 deletions

View File

@ -1029,7 +1029,7 @@ class SSTemplateParser extends Parser {
} }
/* ElseIfPart: '<%' < 'else_if' [ :IfArgument > '%>' :Template? */ /* ElseIfPart: '<%' < 'else_if' [ :IfArgument > '%>' :Template */
function match_ElseIfPart ($substack = array()) { function match_ElseIfPart ($substack = array()) {
$result = $this->construct( "ElseIfPart" ); $result = $this->construct( "ElseIfPart" );
$_162 = NULL; $_162 = NULL;
@ -1053,19 +1053,12 @@ class SSTemplateParser extends Parser {
$_159 = new ParserExpression( $this, $substack, $result ); $_159 = new ParserExpression( $this, $substack, $result );
if (( $subres = $this->literal( $_159->expand('%>') ) ) !== FALSE) { $result["text"] .= $subres; } if (( $subres = $this->literal( $_159->expand('%>') ) ) !== FALSE) { $result["text"] .= $subres; }
else { $_162 = FALSE; break; } else { $_162 = FALSE; break; }
$res_161 = $result;
$pos_161 = $this->pos;
$key = "Template"; $pos = $this->pos; $key = "Template"; $pos = $this->pos;
$subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->match_Template(array_merge($substack, array($result))) ) ); $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->match_Template(array_merge($substack, array($result))) ) );
if ($subres !== FALSE) { if ($subres !== FALSE) {
$this->store( $result, $subres, "Template" ); $this->store( $result, $subres, "Template" );
} }
else { else { $_162 = FALSE; break; }
$result = $res_161;
$this->pos = $pos_161;
unset( $res_161 );
unset( $pos_161 );
}
$_162 = TRUE; break; $_162 = TRUE; break;
} }
while(0); while(0);
@ -1076,7 +1069,7 @@ class SSTemplateParser extends Parser {
} }
/* ElsePart: '<%' < 'else' > '%>' :Template? */ /* ElsePart: '<%' < 'else' > '%>' :Template */
function match_ElsePart ($substack = array()) { function match_ElsePart ($substack = array()) {
$result = $this->construct( "ElsePart" ); $result = $this->construct( "ElsePart" );
$_173 = NULL; $_173 = NULL;
@ -1092,19 +1085,12 @@ class SSTemplateParser extends Parser {
$_170 = new ParserExpression( $this, $substack, $result ); $_170 = new ParserExpression( $this, $substack, $result );
if (( $subres = $this->literal( $_170->expand('%>') ) ) !== FALSE) { $result["text"] .= $subres; } if (( $subres = $this->literal( $_170->expand('%>') ) ) !== FALSE) { $result["text"] .= $subres; }
else { $_173 = FALSE; break; } else { $_173 = FALSE; break; }
$res_172 = $result;
$pos_172 = $this->pos;
$key = "Template"; $pos = $this->pos; $key = "Template"; $pos = $this->pos;
$subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->match_Template(array_merge($substack, array($result))) ) ); $subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->match_Template(array_merge($substack, array($result))) ) );
if ($subres !== FALSE) { if ($subres !== FALSE) {
$this->store( $result, $subres, "Template" ); $this->store( $result, $subres, "Template" );
} }
else { else { $_173 = FALSE; break; }
$result = $res_172;
$this->pos = $pos_172;
unset( $res_172 );
unset( $pos_172 );
}
$_173 = TRUE; break; $_173 = TRUE; break;
} }
while(0); while(0);
@ -1174,14 +1160,14 @@ class SSTemplateParser extends Parser {
function If_IfPart(&$res, $sub) { function If_IfPart(&$res, $sub) {
$res['php'] = $res['php'] =
'if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL . 'if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL .
$sub['Template']['php'] . PHP_EOL . (isset($sub['Template']) ? $sub['Template']['php'] : '') . PHP_EOL .
'}'; '}';
} }
function If_ElseIfPart(&$res, $sub) { function If_ElseIfPart(&$res, $sub) {
$res['php'] .= $res['php'] .=
'else if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL . 'else if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL .
$sub['Template']['php'] . PHP_EOL . $sub['Template']['php'] . PHP_EOL .
'}'; '}';
} }

View File

@ -338,22 +338,22 @@ class SSTemplateParser extends Parser {
# argument structure to every other block # argument structure to every other block
IfPart: '<%' < 'if' [ :IfArgument > '%>' :Template? IfPart: '<%' < 'if' [ :IfArgument > '%>' :Template?
ElseIfPart: '<%' < 'else_if' [ :IfArgument > '%>' :Template? ElseIfPart: '<%' < 'else_if' [ :IfArgument > '%>' :Template
ElsePart: '<%' < 'else' > '%>' :Template? ElsePart: '<%' < 'else' > '%>' :Template
If: IfPart ElseIfPart* ElsePart? '<%' < 'end_if' > '%>' If: IfPart ElseIfPart* ElsePart? '<%' < 'end_if' > '%>'
*/ */
function If_IfPart(&$res, $sub) { function If_IfPart(&$res, $sub) {
$res['php'] = $res['php'] =
'if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL . 'if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL .
$sub['Template']['php'] . PHP_EOL . (isset($sub['Template']) ? $sub['Template']['php'] : '') . PHP_EOL .
'}'; '}';
} }
function If_ElseIfPart(&$res, $sub) { function If_ElseIfPart(&$res, $sub) {
$res['php'] .= $res['php'] .=
'else if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL . 'else if (' . $sub['IfArgument']['php'] . ') { ' . PHP_EOL .
$sub['Template']['php'] . PHP_EOL . $sub['Template']['php'] . PHP_EOL .
'}'; '}';
} }

View File

@ -278,6 +278,10 @@ after')
// Else // Else
$this->assertEquals('ADE', $this->assertEquals('ADE',
$this->render('A<% if Right == Wrong %>B<% else_if RawVal != RawVal %>C<% else %>D<% end_if %>E')); $this->render('A<% if Right == Wrong %>B<% else_if RawVal != RawVal %>C<% else %>D<% end_if %>E'));
// Empty if with else
$this->assertEquals('ABC',
$this->render('A<% if NotSet %><% else %>B<% end_if %>C'));
} }
function testBaseTagGeneration() { function testBaseTagGeneration() {