Forum Discussion
Deb_Allen_18
May 18, 2005Historic F5 Account
substr function with termination character
BIG-IP v 9.0.5
trying to optimize some rules, and using substr with a termination character doesn't seem to work...
It seems to re-init the system and I lose SSH connectivity, and nothing further is processed by the rule.
For instance, I connect to the VS with the following rule as resource:
when HTTP_REQUEST {
set inbound_uri [string tolower [HTTP::uri]]
log "inbound_uri: $inbound_uri"
log "[substr $inbound_uri 1]"
log "[substr $inbound_uri 1 /]"
pool Test-Pool
}
and I see ONLY the handshake in a trace (no request packet is captured) and NONE of the expected log lines appear in the log. (Although it seems pretty clear that the request is being received by the BIG-IP, but are just not being captured or logged before the error I seem to be encountering restarts the services...)
If I comment out the 3rd log command, I see the expected behaviour: the handshake AND the request in a trace, and the first 2 log messages in the log with the expected substitutions.
I've tried with different termination chars, same difference. (Forward slash doesn't need to be quoted or escaped, does it?)
Am I doing something wrong here?
thx
/deb
7 Replies
- Deb,
The terminator optional argument to the substr command needs to be a string or a length. In your case, /, isn't either. Try enclosing the terminator argument with quotes like this:when HTTP_REQUEST { set inbound_uri [string tolower [HTTP::uri]] log "inbound_uri: $inbound_uri" log "[substr $inbound_uri 1]" log "[substr $inbound_uri 1 "/"]" pool Test-Pool }
-Joe - unRuleY_95363Historic F5 AccountActually, you are running into a bug (CR48097) which is fixed in our next maintenance release coming out soon. You can also contact support to get a hotfix for 9.0.5 (just reference the above CR).
- Deb_Allen_18Historic F5 AccountI've requested the hotfix, thank for the heads up!
/deb - Deb_Allen_18Historic F5 AccountThanks Joe.
I wondered about that myself. Since "/" isn't a "special character", I figured it would actually be interpreted as a string and didn't require escaping or quoting.
when it didn't work, I tried it quoted, and either syntax was acceptable (to the parser at least.)
Is it always safe to quote a string? What is the recommended best practice?
thanks
/deb - Deb_Allen_18Historic F5 Account
I forgot to ask --
Once I get the hotfix in place, will I need to quote the "/"?
thx again
/deb - unRuleY_95363Historic F5 AccountNo, you should not need to quote the /. In general, the only time you need to quote something is if it contains spaces.
However, I often find myself quoting strings to help remind me that it is a string literal vs. a Tcl command.
Also note that using braces {} often accomplishes the same effect as quoting, but with a subtle difference. Braces create a Tcl list, which when referred to as a complete entity appears the same as a quoted string. So, in the example below, the two forms are generally equivalent unless a particular command is expecting a list, then the latter form is required:set bar "This is a string" set foo {This is a list}
However, there is a subtle performance difference between the two. The list causes Tcl to allocate a list object containing each list element in its own a seperate object. So, though the intended result appears the same, the list form has a larger impact on performance.
Hope this helps. - Deb_Allen_18Historic F5 Accountexcellent information, thank you.
I was hoping to understand that better.
I'll post another question about use of curly brackets...
thanks again
/d
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
