Parsing S50:Cookie Using E130

Options
Hello,


I am using some sample code I found in a thread ( https://community.blackbaud.com/forums/viewtopic/1/20?post_id=12826#p12826 ) but it only works some of the time:

[[?[[S50:Cookie]]::myCookie=::[[U1:myCookie=[[E130:[[T8:[[S50:Cookie]]]] dup dup "myCookie=" indexof 9 + swap length substring dup 0 swap ";" indexof substring]]]]  verify myCookie: [[S80:myCookie]] ::myCookie not found]]


The problem is the syntax above only works whenever myCookie is not at the end of the chain.

Example where it works:

JSESSIONID=3AA9888DB4EC91045417885359D53CEA.app202b; myCookie=chocolate; another-cookie=raisin


Example where it fails:

JSESSIONID=3AA9888DB4EC91045417885359D53CEA.app202b; another-cookie=raisin; myCookie=chocolate


How do I use E130 to either find myCookie wherever it is in the chain or test for it at the end of the chain? Either solution would work but I'd prefer to be able to find and use the value of myCookie regardless of where it renders using S50:Cookie.


Thanks!
Tagged:

Comments

  • Try:

    [[?[[S50:Cookie]]::myCookie=:: [[U1:myCookie=[[E130:[[T8:[[S50:Cookie]];]] dup dup "myCookie=" indexof 9 + swap length substring dup 0 swap ";" indexof substring]]]] verify myCookie: [[S80:myCookie]] :: myCookie not found ]]


    By adding a semi-colon after the cookie string, you guarantee there will always be one after the cookie.
  • Noah Cooper:

    Try:

    [[?[[S50:Cookie]]::myCookie=:: [[U1:myCookie=[[E130:[[T8:[[S50:Cookie]];]] dup dup "myCookie=" indexof 9 + swap length substring dup 0 swap ";" indexof substring]]]] verify myCookie: [[S80:myCookie]] :: myCookie not found ]]


    By adding a semi-colon after the cookie string, you guarantee there will always be one after the cookie.

    Thanks, Noah, I figured you'd be the one to ask. :)

    Did adding the semicolon after [[S50:Cookie]] cause the E130 tag to ignore it? I'm still trying to understand the syntax usage. Thanks again.

  • It's not that it is being ignored, it's that adding a semi-colon ensures that there is always one after each cookie key value pair, even the last one in the list. For example, myCookie=foo becomes myCookie=foo; while myCookie=foo; anotherCookie=bar becomes myCookie=foo; anotherCookie=bar;. This way, if you split on the next semi-colon to find the end of the cookie value, it will always be present.


    If you break down the reverse polish notation expression into each step and examine the stack it might make more sense. Step by step, the stack is:


    myCookie=foo;

    myCookie=foo; myCookie=foo;

    myCookie=foo; myCookie=foo; myCookie=foo;

    myCookie=foo; myCookie=foo; myCookie=foo; myCookie=

    myCookie=foo; myCookie=foo; 0

    myCookie=foo; myCookie=foo; 0 9

    myCookie=foo; myCookie=foo; 9

    myCookie=foo; 9 myCookie=foo;

    myCookie=foo; 9 13

    foo;

    foo; foo;

    foo; foo; 0

    foo; 0 foo;

    foo; 0 foo; ;

    foo; 0 3

    foo

Categories