Index: openacs-4/packages/acs-templating/tcl/parse-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/parse-procs.tcl,v diff -u -N -r1.26.2.7 -r1.26.2.8 --- openacs-4/packages/acs-templating/tcl/parse-procs.tcl 2 Feb 2005 15:55:44 -0000 1.26.2.7 +++ openacs-4/packages/acs-templating/tcl/parse-procs.tcl 21 Nov 2005 17:28:14 -0000 1.26.2.8 @@ -370,17 +370,19 @@ # array variables # TODO: ad_quotehtml # TODO: lang::util::localize - regsub {^%([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)%$} $substitution {$\1(\2)} substitution - # ordinary variables - regsub {^%([a-zA-Z0-9_:]+)%$} $substitution {$\1} substitution - # Create command to execute in caller's scope - set command "subst -nocommands \"$substitution\"" - - # and execute that - set substitution [uplevel $command] + regsub -all {[\]\[\{\}\"]\\$} $substitution {\\&} substitution + if { [regexp {^%([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)%$} $substitution match arr key] } { + # the array key name is substitured by the tcl parser s + regsub -all {[\]\[\{\}\"]\\$} $key {\\&} key + set substitution [uplevel $command] + } + if { [regexp {^%([a-zA-Z0-9_:]+)%$} $substitution match var] } { + set command "set $var" + set substitution [uplevel $command] + } } - + append formatted_message $substitution } Index: openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl,v diff -u -N -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl 1 Jan 2005 18:45:32 -0000 1.1.2.1 +++ openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl 21 Nov 2005 17:28:15 -0000 1.1.2.2 @@ -49,4 +49,31 @@ } +} + +aa_register_case -cats {api smoke} expand_percentage_signs { + Test expand percentage signs to make sure it substitures correctly + + @author Dave Bauer + @creation-date 2005-11-20 +} { + set orig_message "Test message %one%" + set one "\[__does_not_exist__\]" + set message $orig_message + + aa_false "Expanded square bracket text" [catch {set expanded_message [template::expand_percentage_signs $message]} errmsg] + aa_log $errmsg + aa_equals "square brackets safe" $expanded_message "Test message \[__does_not_exist__\]" + + set one "\$__does_not_exist" + aa_false "Expanded dollar test" [catch {set expanded_message [template::expand_percentage_signs $message]} errmsg] + aa_log $errmsg + aa_equals "dollar sign safe" $expanded_message "Test message \$__does_not_exist" + + set one "\$two(\$three(\[__does_not_exist\]))" + + aa_false "Square bracket in array key test" [catch {set expanded_message [template::expand_percentage_signs $message]} errmsg] + aa_log $errmsg + aa_equals "square brackets in array key safe" $expanded_message "Test message \$two(\$three(\[__does_not_exist\]))" + } \ No newline at end of file