From f77824eef58b54a1726833db8273ee8fec5606d6 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 25 Sep 2001 21:34:08 +0000 Subject: [PATCH] Fixed line number reporting when removing comments. --- NEWS | 4 +++- Smarty_Compiler.class.php | 12 +++++++----- libs/Smarty_Compiler.class.php | 12 +++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 053e3d84..8606628b 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ - - made html_options output xhtml compatible (Monte, Arnaud Limbourg) + - added fix for removing comments so that the line numbers are reported + correctly in case of errors. (patch from Anders Janson) + - made html_options output xhtml compatible code. (Monte, Arnaud Limbourg) Version 1.4.5 ------------- diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 023eaad0..43b88ed8 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -80,11 +80,9 @@ class Smarty_Compiler extends Smarty { $rdq = preg_quote($this->right_delimiter, '!'); /* Annihilate the comments. */ - if (preg_match_all("!{$ldq}\*.*?\*{$rdq}!s", $template_source, $match)) { - foreach ($match[0] as $comment) - $this->_current_line_no += substr_count($comment, "\n"); - $template_source = preg_replace("!{$ldq}\*.*?\*{$rdq}!s", '', $template_source); - } + $template_source = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se", + "'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'", + $template_source); /* Pull out the literal blocks. */ preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_source, $match); @@ -175,6 +173,10 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _compile_tag($template_tag) { + /* Matched comment. */ + if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*') + return ''; + $qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\''; /* Split tag into two parts: command and the arguments. */ diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 023eaad0..43b88ed8 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -80,11 +80,9 @@ class Smarty_Compiler extends Smarty { $rdq = preg_quote($this->right_delimiter, '!'); /* Annihilate the comments. */ - if (preg_match_all("!{$ldq}\*.*?\*{$rdq}!s", $template_source, $match)) { - foreach ($match[0] as $comment) - $this->_current_line_no += substr_count($comment, "\n"); - $template_source = preg_replace("!{$ldq}\*.*?\*{$rdq}!s", '', $template_source); - } + $template_source = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se", + "'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'", + $template_source); /* Pull out the literal blocks. */ preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_source, $match); @@ -175,6 +173,10 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _compile_tag($template_tag) { + /* Matched comment. */ + if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*') + return ''; + $qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\''; /* Split tag into two parts: command and the arguments. */