Forum Discussion

kpiti_52215's avatar
kpiti_52215
Icon for Nimbostratus rankNimbostratus
Jan 29, 2013

lsearch nocase bug or what?

I wanted to use case insensitive list search but I got an error back. Try this proof-of-concept iRule:

when CLIENT_ACCEPTED {
  TCP::collect
}
when CLIENT_DATA {
  set list [split [TCP::payload] foo]
  if { [lsearch -all -nocase $list bar] >= 0 } {
    log local0. "match"
  }
}

What I get back is:

01070151:3: Rule [/Common/TestLsearch] error:

 

line 6: [invalid switch: "-nocase"] [-nocase]

Apart from TCL lsearch specs, this example is even mentioned in Colin's iRules guide Case Insensitive Comparisons

lsearch -all -nocase {a b c a b c} C

I'm running 11.1.0 for reference..

Is this a bug or is there some deeper reason for this?

Jure

3 Replies

  • Hi Jure,

     

     

    iRules are based on 8.4 Tcl. The -nocase flag was added to lsearch in 8.5:

     

     

    http://www.tcl.tk/man/tcl8.4/TclCmd/lsearch.htm

     

    http://www.tcl.tk/man/tcl8.5/TclCmd/lsearch.htm

     

     

    Can you set the list you're searching and the search term in lowercase?

     

     

    set list [split [string tolower [TCP::payload]] foo]

     

    if { [lsearch -all -nocase $list bar] >= 0 } {

     

     

    Aaron
  • Thanks Aaron,

     

    that explains it. I will do a workaround with a lowercase copy of the payload and doing changes on the real payload.

     

    I guess someone should notify Colin about this as well =)

     

     

    Jure