cookie voodoo

From: CHYRON (DSMITHHFX)25 Jul 2015 16:03
To: Peter (BOUGHTONP) 3 of 10
I did make some edits to the javascript yesterday unrelated to the cookies stuffs. I'll do a diff compare to previous version on monday.
From: CHYRON (DSMITHHFX)27 Jul 2015 12:53
To: ALL4 of 10
Problem solved by deletion of a single caricature.

Before:
Code: 
document.cookie.match(/^foliosec=[a-z]+/) + '';
After:
Code: 
document.cookie.match(/foliosec=[a-z]+/) + '';
From: 99% of gargoyles look like (MR_BASTARD)27 Jul 2015 16:50
To: Peter (BOUGHTONP) 5 of 10
G'wan, tell him the difference between 'caricature' and 'character', and let him squirm at his risible use of language. You know you want to.
From: CHYRON (DSMITHHFX)27 Jul 2015 19:17
To: 99% of gargoyles look like (MR_BASTARD) 6 of 10
Caricature: you. Character: Peter.

You're welcome.
From: Peter (BOUGHTONP)27 Jul 2015 19:44
To: CHYRON (DSMITHHFX) 7 of 10
Except now it'll also match any cookies with names ending in "portfoliosec".

If JS had a decent regex engine, you'd just use a lookbehind instead (?<=^|;) but it doesn't so that wont work.

Next best solution is probably splitting and looping:

FoliosecCookie = getCookie('foliosec');

function getCookie( Name )
{
	for ( CurCookie in document.cookie.split(';') )
	{
	    var KeyValue = CurCookie.split('=',2);
	    if ( KeyValue[0] == Name )
	       return KeyValue[1];
	}
	return '';
}

You may need to use decodeURIComponent on the return value.

And for anyone wondering why the browsers don't just provide a built-in getCookie method that accepts a name and returns the value, the answer is because browser developers are fucking stupid.

From: CHYRON (DSMITHHFX)27 Jul 2015 20:02
To: Peter (BOUGHTONP) 8 of 10
I could have tried
/; foliosec=[a-z]+;/
but I was too lazy to find out if semi-colons need to be escaped (as seems likely), didn't want to start faffing around with regex voodoo, and was tickled by the one-caricature fix (apologies to bastard for that).

The likelihood of another cookie that includes "foliosec" as part of its name in this site is remote.

I'm considering whether using cookies makes the whole thing a bit too fragile, and will try url-based variables instead, which is how e.g. angularjs does it.
EDITED: 27 Jul 2015 20:08 by DSMITHHFX
From: Peter (BOUGHTONP)27 Jul 2015 23:15
To: CHYRON (DSMITHHFX) 9 of 10
Semi-colon doesn't need escaping. Only these do: ^.$*+?\|()[]{}

And it really isn't voodoo; it's a very easy language to learn.

From: CHYRON (DSMITHHFX)29 Jul 2015 00:45
To: ALL10 of 10
Got the URL-based vars coded up without too much trouble (even learned the simple trick of rewriting the URL hash on the fly) and it seems considerably more responsive than the cookie vars. Probly make the patches live tomorrow.