Forum Discussion

JamesS_40157's avatar
JamesS_40157
Icon for Nimbostratus rankNimbostratus
Jun 26, 2013

TCL error "bad option" with minus character

Hi,

 

We have an iRule that tries to match user agents against a datagroup - this has been working fine for a while however recently we've seen a bunch of TCL errors show up, that I believe are due to the user-agent beginning with a minus character:

 

 

- bad option "-1'": must be -all, -index, -element, -name, or -value while executing "class match [string tolower [HTTP::header "User-Agent"]] contains mobileUserAgents"

 

 

It seems like TCL is expanding the string and interpreting it as an option rather than just a string used to match against a datagroup. What would be the best way to mitigate against this and use it as just a string? Can we wrap double quotes around it or do we have to sanitise it further, such as looking for a "-" at the beginning and stripping it out before doing the class match?

 

 

Thanks in advance

 

james

 

2 Replies

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi James,

     

     

    You can use -- to terminate the options for the class command:

     

     

    class match -- [string tolower [HTTP::header "User-Agent"]] contains mobileUserAgents

     

     

    https://devcentral.f5.com/wiki/iRules.class.ashx

     

    -- Terminates option processing (useful if the or begins with a hyphen).

     

     

    Aaron