Forum OpenACS Q&A: <include> template encodes html

Collapse
Posted by Stephen Saunders on
Recently at work, we came across a bug in our error page (ironic, I know). It involves a browser page printing the stacktrace of tcl. The page is supposed to show something like this:
I'm an error
    while executing
"error "I'm an error""
    ("uplevel" body line 13)
    invoked from within
"uplevel {
# /packages/my-package/www/form.tcl

ad_page_contract {
  @author Stephen Saunders
 ..."
    (procedure "code::tcl::/web/sites/ssaunders/packages/my-package/w..." line 2)
    invoked from within
"code::tcl::$__adp_stub"
    ("uplevel" body line 12)
    invoked from within
"uplevel {
However, the trace displayed with the HTML encoding:
hello
    while executing
"error "hello""
    ("uplevel" body line 13)
    invoked from within
"uplevel {
# /packages/my-package/www/form.tcl

ad_page_contract {
  @author Stephen Saunders
 ..."
    (procedure "code::tcl::/web/sites/ssaunders/packages/my-package/w..." line 2)
    invoked from within
"code::tcl::$__adp_stub"
    ("uplevel" body line 12)
    invoked from within
"uplevel {

Really annoying to read. We discovered that the stacktrace was being passed via an include tag to a template.

 <include src="wt-error" stacktrace="@stacktrace@" />

Which was then put into an html fragment.

 <pre>@stacktrace@</pre>

This meant the stacktrace was getting quoted twice. We solved the issue by adding ;noquote to the include.

So now a question. Is this/should this be expected behavior? It is not documented anywhere that I could find, especially on the include tag reference (https://openacs.org/doc/acs-templating/tagref/include.html), where it would be most important.

Collapse
Posted by Gustaf Neumann on
Hi Stephen,

The best way to pass values to an includelet is either to use noquote on the include line or to pass the value by reference. The problem you are observing is that the passed argument value (between @-characters) is quoted during the @-substituion of the include arguments, and if the variable is used a second time in the @-notation (in the included snippet), it is quoted again.

Look below for the interesting cases. In (1). there is no @ involved, therefore it is passed as value and needs quoting in the included adp snippet. In (2) we assume we have a variable named 'var' with a value '<'. The value is quoted during the substitution of @var@. In case (3) we use noquote, and in case (4) we use the call-by reference pattern. I would assume that for most uses, call-by-reference is appropriate.

<master>
  <property name="doc(title)">@page_title;noquote@</property>
  <property name="context">@context;noquote@</property>

1: <include src="./i" attribute='<'><hr>
2: <include src="./i" attribute='@var@'><hr>
3: <include src="./i" attribute='@var;noquote@'><hr>
4: <include src="./i" &attribute='var'>
Hope this helps
-gustaf
Collapse
Posted by Stephen Saunders on
Gustaf,

Thank you for your response. The larger question I am trying to raise is should this property be mentioned in the tag documentation? I couldn't find it when I looked.

Collapse
Posted by Gustaf Neumann on
yes, it should. no question. -g
Collapse
Posted by Stephen Saunders on
How would I go about suggesting that?
Collapse
Posted by Gustaf Neumann on
Dear Stephen,

The easiest is probably to write a short bug-report on [1] and to provide - if possible - a patch for packages/acs-templating/www/doc/tagref/include.html

all the best
-gustaf

[1] https://openacs.org/bugtracker/openacs/

Collapse
Posted by Stephen Saunders on
I will do that. Thank you.
Collapse
Posted by Gustaf Neumann on
Thank you as well. Please, also other users, when you see something that bugs you, please make a bug report!