Forum Discussion

swabbies_112156's avatar
swabbies_112156
Icon for Nimbostratus rankNimbostratus
Jan 09, 2013

help with syntax for trim command

Hello.

 

I am trying to sort out the correct syntax for using the trim function to get rid of any whitespace at the end of value.

 

 

exsting code: set cmd [ URI::query [string tolower [HTTP::uri]] command ]

 

example uri that works correctly = /interface.asp?command=testfunction&uid=testuser1

 

this then sets "cmd" to "testfunction"

 

 

example uri tdoesn't work because of whitespace = /interface.asp?command=testfunction &uid=testuser1

 

this sets "cmd" to "testfunction%20" and causes issues.

 


 

Would this be the correct syntax? and would this cover requests that have 2 whitespaces in it or only 1?

 

 

set cmd [string trim [URI::query [string tolower [HTTP::uri]] " "] command ]

 

 

Thanks for your help.

 

Ben

 

4 Replies

  • Hi Ben,

     

     

    The user-agent should be URI encoding the space into a %20 before sending the HTTP request. String trim works fine when you want to trim any set of individual characters but not a specific sequence. If you want to remove the %20's from a parameter value, you can try this:

     

     

    set cmd [string map {%20 ""} [URI::query [string tolower [HTTP::uri]] " "] command]]

     

     

    Just make sure to test the config load after you make the iRule change using 'b verify load' or 'tmsh load sys config verify'. There have been some parser bugs when loading the config with these types of commands. If you see any issues reply back here and I'll try giving you an alternate format to do the same thing.

     

     

    Aaron
  • Aaron,

     

    Thanks for your help.

     

     

    did you mean to put :

     

    set cmd [string map {%20 ""} [ URI::query [string tolower [HTTP::uri]] command ]]

     

     

    instead of:

     

    set cmd [string map {%20 ""} [URI::query [string tolower [HTTP::uri]] " "] command]]
  • i think so.

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when RULE_INIT {
      set uri "/interface.asp?command=testfunction%20&uid=testuser1"
      log local0. "\[string map {%20 \"\"} \[URI::query [string tolower $uri] command\]\]=.[string map {%20 ""} [URI::query [string tolower $uri] command]]."
    }
    }
    
    [root@ve10:Active] config  tail /var/log/ltm
    Jan 10 00:28:47 local/tmm info tmm[4884]: Rule myrule : [string map {%20 ""} [URI::query /interface.asp?command=testfunction%20&uid=testuser1 command]]=.testfunction.