diff --git a/view/SSTemplateParser.php b/view/SSTemplateParser.php index 662662107..c3e3532b6 100644 --- a/view/SSTemplateParser.php +++ b/view/SSTemplateParser.php @@ -4608,13 +4608,27 @@ class SSTemplateParser extends Parser { // if not, put it after the tag to avoid IE glitches if(stripos($code, "]*("[^"]")*[^>]*>)/im', "$1\r\n", $code); + $code .= "\r\n" . '$val .= \'\';'; } elseif(stripos($code, "]*>)/i', "$1", $code); + $code = preg_replace_callback('/(.*)(]*>)(.*)/i', function($matches) use ($templateName) { + if (stripos($matches[3], '') !== false) { + // after this tag there is a comment close but no comment has been opened + // this most likely means that this tag is inside a comment + // we should not add a comment inside a comment (invalid html) + // lets append it at the end of the comment + // an example case for this is the html5boilerplate: + return $matches[0]; + } else { + // all other cases, add the comment and return it + return "{$matches[1]}{$matches[2]}{$matches[3]}"; + } + }, $code); + $code = preg_replace('/(<\/html[^>]*>)/i', "$1", $code); } else { $code = str_replace('\';' . "\r\n", $code); + $code .= "\r\n" . '$val .= \'\';'; } - $code .= "\r\n" . '$val .= \'\';'; return $code; } diff --git a/view/SSTemplateParser.php.inc b/view/SSTemplateParser.php.inc index 75ccdaffa..68249b3ed 100644 --- a/view/SSTemplateParser.php.inc +++ b/view/SSTemplateParser.php.inc @@ -1062,13 +1062,27 @@ class SSTemplateParser extends Parser { // if not, put it after the tag to avoid IE glitches if(stripos($code, "]*("[^"]")*[^>]*>)/im', "$1\r\n", $code); + $code .= "\r\n" . '$val .= \'\';'; } elseif(stripos($code, "]*>)/i', "$1", $code); + $code = preg_replace_callback('/(.*)(]*>)(.*)/i', function($matches) use ($templateName) { + if (stripos($matches[3], '') !== false) { + // after this tag there is a comment close but no comment has been opened + // this most likely means that this tag is inside a comment + // we should not add a comment inside a comment (invalid html) + // lets append it at the end of the comment + // an example case for this is the html5boilerplate: + return $matches[0]; + } else { + // all other cases, add the comment and return it + return "{$matches[1]}{$matches[2]}{$matches[3]}"; + } + }, $code); + $code = preg_replace('/(<\/html[^>]*>)/i', "$1", $code); } else { $code = str_replace('\';' . "\r\n", $code); + $code .= "\r\n" . '$val .= \'\';'; } - $code .= "\r\n" . '$val .= \'\';'; return $code; }