Forum OpenACS Development: Quoting curly braces in adp:s

Collapse
Posted by Peter Marklund on
I wanted to include a curly brace in my adp page and found that the templating system would break. It seems they forgot to quote curly braces so I added that. Where it would previously say:
# protect double quotes, brackets, the dollar sign, and backslash
regsub -all {[][""\$]} $remaining {\&} quoted
I changed it to say
adp_append_string [adp_quote_chunk $remaining]
and added the following proc
ad_proc -private template::adp_quote_chunk { chunk } {
  Return the given adp chunk with all square brackets and curly braces
  dollar signs, and double quotes quoted (preceded by a backslash).

  @author Peter Marklund (peter@collaboraid.biz)

  @creation-date 2002-10-15
} {
  regsub -all {[][{}"\$]} $chunk {\&} quoted

  return $quoted
}
I was just wondering if there is any performance concern in adding a proc here. I guess it's slightly less efficient than the inline regsub. Otherwise, if what I've done seems ok I'll go ahead and commit this.
Collapse
Posted by Peter Marklund on
I changed the proc to use upvar instead:
ad_proc -private template::adp_quote_chunk { chunk_var_name quoted_var_name } {
  Quotes (precedes by backslash) all square brackets, curly braces, 
  double quotes, backslashes, and dollar signs in a chunk of adp.

  @param chunk_var_name  The name of the variable to quote
  @param quoted_var_name The name of the variable to put the quoted result in

  @author Peter Marklund (peter@collaboraid.biz)

  @creation-date 2002-10-16
} {
  upvar $chunk_var_name chunk $quoted_var_name quoted

  regsub -all {[][{}"\$]} $chunk {\&} quoted
}
and calling the proc now becomes:
adp_quote_chunk remaining remaining_quoted
Does using upvar consume less memory, is it faster? Should I be using upvar here?
Collapse
Posted by Peter Marklund on
I committed the latter version of the proc to CVS so that curly braces are now quoted.

/Peter

Collapse
Posted by Jeff Davis on
We should probably call this something different and more in line
with what it does not where it is being called from.  Say
ad_quotetcl (or since we are not aD anymore maybe just util_quotetcl
or something).

There are other places besides just adp pages that tcl needs to be quoted.