From d190c1c8fd7034715b1e4da61d49412c46b48a65 Mon Sep 17 00:00:00 2001 From: mohrt Date: Wed, 19 Feb 2003 15:58:03 +0000 Subject: [PATCH] allow null as function attribute value --- NEWS | 2 ++ Smarty_Compiler.class.php | 13 +++++++++---- libs/Smarty_Compiler.class.php | 13 +++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 1a4781a7..e31b6832 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - allow null as function attribute value + (André Rabold, Monte) - support $foo->bar[index] syntax (Monte) - add get_registered_object function (messju, Monte) - treat unrecognized param attribute syntax as string (Monte) diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index ae015dcf..d2126ff4 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -53,7 +53,7 @@ class Smarty_Compiler extends Smarty { var $_capture_stack = array(); // keeps track of nested capture buffers var $_plugin_info = array(); // keeps track of plugins to load var $_init_smarty_vars = false; - var $_permitted_tokens = array('true','false','yes','no','on','off'); + var $_permitted_tokens = array('true','false','yes','no','on','off','null'); var $_db_qstr_regexp = null; // regexps are setup in the constructor var $_si_qstr_regexp = null; var $_qstr_regexp = null; @@ -659,9 +659,12 @@ class Smarty_Compiler extends Smarty { $arg_list = array(); $attrs = $this->_parse_attrs($tag_args); + foreach ($attrs as $arg_name => $arg_value) { if (is_bool($arg_value)) $arg_value = $arg_value ? 'true' : 'false'; + if (is_null($arg_value)) + $arg_value = 'null'; $arg_list[] = "'$arg_name' => $arg_value"; } @@ -1342,9 +1345,11 @@ class Smarty_Compiler extends Smarty { /* We booleanize the token if it's a non-quoted possible boolean value. */ if (preg_match('!^(on|yes|true)$!', $token)) { - $token = true; + $token = 'true'; } else if (preg_match('!^(off|no|false)$!', $token)) { - $token = false; + $token = 'false'; + } else if ($token == 'null') { + $token = 'null'; } else if (!preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')?$!', $token)) { /* treat as a string, double-quote it escaping quotes */ $token = '"'.addslashes($token).'"'; @@ -1368,7 +1373,7 @@ class Smarty_Compiler extends Smarty { } $this->_parse_vars_props($attrs); - + return $attrs; } diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index ae015dcf..d2126ff4 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -53,7 +53,7 @@ class Smarty_Compiler extends Smarty { var $_capture_stack = array(); // keeps track of nested capture buffers var $_plugin_info = array(); // keeps track of plugins to load var $_init_smarty_vars = false; - var $_permitted_tokens = array('true','false','yes','no','on','off'); + var $_permitted_tokens = array('true','false','yes','no','on','off','null'); var $_db_qstr_regexp = null; // regexps are setup in the constructor var $_si_qstr_regexp = null; var $_qstr_regexp = null; @@ -659,9 +659,12 @@ class Smarty_Compiler extends Smarty { $arg_list = array(); $attrs = $this->_parse_attrs($tag_args); + foreach ($attrs as $arg_name => $arg_value) { if (is_bool($arg_value)) $arg_value = $arg_value ? 'true' : 'false'; + if (is_null($arg_value)) + $arg_value = 'null'; $arg_list[] = "'$arg_name' => $arg_value"; } @@ -1342,9 +1345,11 @@ class Smarty_Compiler extends Smarty { /* We booleanize the token if it's a non-quoted possible boolean value. */ if (preg_match('!^(on|yes|true)$!', $token)) { - $token = true; + $token = 'true'; } else if (preg_match('!^(off|no|false)$!', $token)) { - $token = false; + $token = 'false'; + } else if ($token == 'null') { + $token = 'null'; } else if (!preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')?$!', $token)) { /* treat as a string, double-quote it escaping quotes */ $token = '"'.addslashes($token).'"'; @@ -1368,7 +1373,7 @@ class Smarty_Compiler extends Smarty { } $this->_parse_vars_props($attrs); - + return $attrs; }