I had to dig a little bit to found out why the "not" wasn't working with the ends_with operator. Well, it seems that the expansion of the "str1 ends_with str2" occurs after the evaluation of the "not". So, the not operator is getting the string "$uri_info ends_with /" which is why you are getting the error stating that
can't use non-numeric string as operand of "!"
I'll check with unRuleY why this is the case and see if this is something we can fix in a future release.
Also, just to make note that the "/" character does not need to be escaped so all those backslashes aren't needed.
So, what do you do? Well, the previous post answers it for now. I'd suggest you just put your code in the else section like the following
when HTTP_REQUEST {
set uri_info [HTTP::uri];
log "Variable uri_info contents: $uri_info";
if { $uri_info ends_with "/" } {
log "Variable uri_info already ends with /";
} else {
append uri_info "/";
HTTP::uri $uri_info;
log "Variable uri_info contents with / appended: $uri_info";
}
}
*Note, I've added the "HTTP::uri $uri_info" after the append so that the change will take.
Another option, since you are only looking for the last character in the string, is to use the builtin "string index" TCL command (
Click here) along with an string comparison operator
when HTTP_REQUEST {
set uri_info [HTTP::uri];
log "Variable uri_info contents: $uri_info"
if { [string index $uri_info end] eq "/" } {
log "Variable uri_info already ends with /";
} else {
append uri_info "/"
HTTP::uri $uri_info;
log "Variable uri_info contents with / appended: $uri_info"
}
}
Or, if you only care about the else clause, you can use the "ne" string operator
when HTTP_REQUEST {
set uri_info [HTTP::uri];
log "Variable uri_info contents: $uri_info"
if { [string index $uri_info end] ne "/" } {
append uri_info "/"
HTTP::uri $uri_info;
log "Variable uri_info contents with / appended: $uri_info"
}
}
-Joe