BUG: Fix for #1487

The parser could sometimes generate invalid code if the
source-file-comments were enabled, this moves the comments outside the
html-tag to circumvent these problems, update test as well.
This commit is contained in:
s-m 2013-04-05 20:00:33 +02:00
parent c02d7e4c2e
commit acf2ff8ce6
3 changed files with 12 additions and 12 deletions

View File

@ -1068,10 +1068,10 @@ after')
$result = $view->process($data); $result = $view->process($data);
$expected = '<!doctype html> $expected = '<!doctype html>
<html><!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsFullSource.ss --> <!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsFullSource.ss --><html>
<head></head> <head></head>
<body></body> <body></body>
<!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsFullSource.ss --></html> </html><!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsFullSource.ss -->
'; ';
$this->assertEquals($result, $expected); $this->assertEquals($result, $expected);

View File

@ -1675,14 +1675,14 @@ class SSTemplateParser extends Parser {
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 .
(isset($sub['Template']) ? $sub['Template']['php'] : '') . PHP_EOL . (isset($sub['Template']) ? $sub['Template']['php'] : '') . PHP_EOL .
'}'; '}';
} }
function If_ElsePart(&$res, $sub) { function If_ElsePart(&$res, $sub) {
$res['php'] .= $res['php'] .=
'else { ' . PHP_EOL . 'else { ' . PHP_EOL .
(isset($sub['Template']) ? $sub['Template']['php'] : '') . PHP_EOL . (isset($sub['Template']) ? $sub['Template']['php'] : '') . PHP_EOL .
'}'; '}';
} }
@ -4593,11 +4593,11 @@ class SSTemplateParser extends Parser {
// Include top level debugging comments if desired // Include top level debugging comments if desired
if($includeDebuggingComments && $templateName && stripos($code, "<?xml") === false) { if($includeDebuggingComments && $templateName && stripos($code, "<?xml") === false) {
// If this template is a full HTML page, then put the comments just inside the HTML tag to prevent any IE // If this template is a full HTML page, then put the comments just outside the HTML tag,
// glitches // this is still no problem for IE as long as the DOCTYPE-declaration is done before this comment
if(stripos($code, "<html") !== false) { if(stripos($code, "<html") !== false) {
$code = preg_replace('/(<html[^>]*>)/i', "\\1<!-- template $templateName -->", $code); $code = preg_replace('/(<html[^>]*>)/i', "<!-- template $templateName -->\\1", $code);
$code = preg_replace('/(<\/html[^>]*>)/i', "<!-- end template $templateName -->\\1", $code); $code = preg_replace('/(<\/html[^>]*>)/i', "\\1<!-- end template $templateName -->", $code);
} else { } else {
$code = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . '$val .= \'<!-- template ' . $templateName . $code = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . '$val .= \'<!-- template ' . $templateName .
' -->\';' . "\n", $code); ' -->\';' . "\n", $code);

View File

@ -1047,11 +1047,11 @@ class SSTemplateParser extends Parser {
// Include top level debugging comments if desired // Include top level debugging comments if desired
if($includeDebuggingComments && $templateName && stripos($code, "<?xml") === false) { if($includeDebuggingComments && $templateName && stripos($code, "<?xml") === false) {
// If this template is a full HTML page, then put the comments just inside the HTML tag to prevent any IE // If this template is a full HTML page, then put the comments just outside the HTML tag,
// glitches // this is still no problem for IE as long as the DOCTYPE-declaration is done before this comment
if(stripos($code, "<html") !== false) { if(stripos($code, "<html") !== false) {
$code = preg_replace('/(<html[^>]*>)/i', "\\1<!-- template $templateName -->", $code); $code = preg_replace('/(<html[^>]*>)/i', "<!-- template $templateName -->\\1", $code);
$code = preg_replace('/(<\/html[^>]*>)/i', "<!-- end template $templateName -->\\1", $code); $code = preg_replace('/(<\/html[^>]*>)/i', "\\1<!-- end template $templateName -->", $code);
} else { } else {
$code = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . '$val .= \'<!-- template ' . $templateName . $code = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . '$val .= \'<!-- template ' . $templateName .
' -->\';' . "\n", $code); ' -->\';' . "\n", $code);