Forum OpenACS Q&A: Forums (HEAD): error when posting

Hi,

I was testing forums on HEAD and ran into the following error when posting to a forum (packages/forums/www/message-post):

syntax error in expression "(834 eq  || 0) && ( eq  || 0)": unexpected operator ||
    while executing
"expr ($forum_id eq "" ||  [forum::security::can_post_forum_p  -forum_id $forum_id -user_id 0]) &&  ($parent_id eq "" ||  [forum::security::can_post_me..."
    invoked from within
"set anonymous_allowed_p [expr ($forum_id eq "" ||  [forum::security::can_post_forum_p  -forum_id $forum_id -user_id 0]) &&  ($parent_id eq "" ||  [for..."
    ("uplevel" body line 57)
    invoked from within
"uplevel {
    	  ad_page_contract {
    
    Form to create message and insert it

    @author Ben Adida (ben@openforce.net)
    @creation-date 2002-0..."
    (procedure "code::tcl::/var/www/openacs-head/packages/forums/w..." line 2)
    invoked from within
"code::tcl::$__adp_stub"
    invoked from within
"if { [file exists $__adp_stub.tcl] } {

      # ensure that data source preparation procedure exists and is up-to-date
      adp_init tcl $__adp_stub
..."
    ("uplevel" body line 3)
    invoked from within
"uplevel {

    if { [file exists $__adp_stub.tcl] } {

      # ensure that data source preparation procedure exists and is up-to-date
      adp_init t..."
    (procedure "adp_prepare" line 2)
    invoked from within
"adp_prepare"
    invoked from within
"template::adp_parse [file root [ad_conn file]] {}"
    (procedure "adp_parse_ad_conn_file" line 6)
    invoked from within
"$handler"
    ("uplevel" body line 2)
    invoked from within
"uplevel $code"
    invoked from within
"ad_try {
                $handler
            } ad_script_abort val {
                # do nothing
            }"
    invoked from within
"rp_serve_concrete_file [ad_conn file]"
    (procedure "rp_serve_abstract_file" line 60)
    invoked from within
"rp_serve_abstract_file "$root/$path""
    ("uplevel" body line 2)
    invoked from within
"uplevel $code"
    invoked from within
"ad_try {
            rp_serve_abstract_file "$root/$path"
            set tcl_url2file([ad_conn url]) [ad_conn file]
            set tcl_url2path_info..."
Collapse
Posted by Stefan Sobernig on
Salut!

Mmmh. When I read you post, I remembered that Prof. Neumann applied a large-scale replacement of numeric comparison operators (==) to string-specific ones (eq, ne), due to the non-neglectable performance gain:

http://fisheye.openacs.org/browse/OpenACS/openacs-4/packages/forums/www/message-post.tcl?r1=1.37&r2=1.38

The issue is that a certain (=non-robust) expr statements turned renegade due to this. By non-robust, I mean that strings get variable etc. substituted before the expression is evaluated. In the concrete example above,

set forum_id 824
## fails: unexpected operator ||
set x [expr ($forum_id eq "" || 0)]
## correct:
set x [expr {($forum_id eq "" || 0)}]

so adding protecting curly braces solves the precedence issue between expression and string evaluation ...

I don't have the time to apply the fix rightnow, if nobody does, I will commit later ... probably other places need to be checked to?

//s

Collapse
Posted by Gustaf Neumann on
I have a short break between two seminars, and fixed the issue above in cvs head.

Btw, the problem is not precedence, but double evaluation, where an empty string resolves in the second evaluation into nothing. expr does its own eval.

The error shows up on:

set x [expr "" eq ""]

-gustaf neumann

Collapse
Posted by Emmanuelle Raffenne on
Salut Stefan, Hi Gustaf,

Thanks to you both. It works as expected now.