Forum Discussion

trx's avatar
Oct 05, 2009

checking URIs for ONLY single worded letters with no spaces

Hello all,

 

My objective is to find out if the incoming URI is a ALL single worded letters.

 

ex)

 

 

URL: http://www.hello.com/

 

GOOD URI:xyx/kkkj/asd

 

BAD URI: xy+/kkkj234

 

BAD URI: xy+/kkk j234/

 

 

As you can see, the logic is I"m checking if the URI contains ONLY letters and are

 

single words with no spaces. Are there any pre-define methods/functions out there that can peform such a check?

 

 

Any help is fully appreciated.

 

 

Thank you.

 

 

Regards,

 

TRX

3 Replies

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

    A space can be encoded as + or %2b in some URL encoders or more typically as %20. Do you want check the full URI or just the path for these characters? Here's an example for checking the path:

     
     when HTTP_REQUEST { 
         Check if path contains +, %2b or %20 
        switch [string tolower [HTTP::path]] { 
           "*+*" - 
           "*%2b*" - 
           "*%20*" { 
               Path contained a "space" character. Do something? 
              log local0. "Found space character in path: [HTTP::path]" 
           } 
        } 
     } 
     

    Aaron
  • The logic would be "If the WHOLE URI ONLY contains alphabet letters with has NO space, then do something....". Are there any predefine functions that checks for only alphabet letters in the URI? Also how what would the syntax be for "DOES NOT CONTAIN SPACES"?

     

     

    Any help is fully appreciated.

     

     

    Thank you.

     

     

    Regards,

     

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

    The previous example would search the path and trigger the log statement if the path contained a space or encoded versions of a space. If you want to instead check for / and any alphanumeric character you could use scan ():

     
     when HTTP_REQUEST { 
         Use scan to read in all characters from a-z, A-Z, 0-9 and / 
           Check if the scanned string is not the entire path 
        if {[scan [HTTP::path] {%[a-zA-Z0-9/]}] ne [HTTP::path]}{ 
           log local0. "Path contained non-alphanumerics and /: [HTTP::path]. matched up to [scan [HTTP::path] {%[a-zA-Z0-9/]}]" 
        } 
     } 
     

    Aaron