Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
3 replies Latest Post - ‏2013-02-28T22:22:55Z by SystemAdmin
SystemAdmin
SystemAdmin
6772 Posts
ACCEPTED ANSWER

Pinned topic PCRE for URI having QueryParameters

‏2013-02-28T02:03:58Z |
Hi All,

I need help to create single PCRE that can accept following URIs

/abc
/abc?token1=12
/abc?token1=12&token2=13
/abc?token2=23
/abc?token2=23&token1=12

and rejects everything else

(Note: Allowed token names are "token1" and "token2". Value of tokens can be anything.)
Thanks
R.G.
Updated on 2013-02-28T22:22:55Z at 2013-02-28T22:22:55Z by SystemAdmin
  • HermannSW
    HermannSW
    4490 Posts
    ACCEPTED ANSWER

    Re: PCRE for URI having QueryParameters

    ‏2013-02-28T08:58:34Z  in response to SystemAdmin
    Hi,

    > (Note: Allowed token names are "token1" and "token2". Value of tokens can be anything.)
    >
    you need to be more specific on "anything".
    I assume that you do not mean to allow for eg. control characters ...

    Below regular expression is for "anything" as "integer numbers", the backslash escapes are needed by the shell:
    $ cat test.inp 
    /abc
    /abc?token1=12
    /abc?token1=12&token2=13
    /abc?token2=23
    /abc?token2=23&token1=12
    /cdf
    /abc#token1=12
    /abc?token3=12
    /abc?token1=
    $ 
    $ grep "^/abc\(\|?token[12]=[1-9][0-9]*\|?token1=[1-9][0-9]*\&token2=[1-9][0-9]*\|?token2=[1-9][0-9]*\&token1=[1-9][0-9]*\)$" test.inp 
    /abc
    /abc?token1=12
    /abc?token1=12&token2=13
    /abc?token2=23
    /abc?token2=23&token1=12
    $
    


     
    Hermann <myXsltBlog/> <myXsltTweets/> <myCE/>
    Updated on 2014-03-25T02:38:34Z at 2014-03-25T02:38:34Z by iron-man
    • HermannSW
      HermannSW
      4490 Posts
      ACCEPTED ANSWER

      Re: PCRE for URI having QueryParameters

      ‏2013-02-28T09:05:32Z  in response to HermannSW
      Perhaps a better idea for you is to use convert-http action in order to convert the query into XML.
      Then you can make use of the full power of Schema validation and validate the XML ...
      $ curl "http://dp3-l3:2227/abc?token1=12&token2=13" -s | tidy -qi -xml 
      <?xml version="1.0" encoding="utf-8"?>
      <request>
        <url>/abc?token1=12&amp;token2=13</url>
        <base-url>/abc</base-url>
        <args src="url">
          <arg name="token1">12</arg>
          <arg name="token2">13</arg>
        </args>
      </request>
       
      $
      


       
      Hermann <myXsltBlog/> <myXsltTweets/> <myCE/>
      Updated on 2014-03-25T02:38:30Z at 2014-03-25T02:38:30Z by iron-man
      • SystemAdmin
        SystemAdmin
        6772 Posts
        ACCEPTED ANSWER

        Re: PCRE for URI having QueryParameters

        ‏2013-02-28T22:22:55Z  in response to HermannSW
        Thanks Herman. I liked the second approach.