Bug in cookie handling code
ErwanLegrand
Status: New User - Welcome
Joined: 05 Nov 2009
Posts: 2
Location: Earth
Reply Quote
Hi,

I've found a bug in the sample code on [new user link].

The Get_cookie() funtion uses global variable "i" as a loop index. Thus, this function overwrites the contents of the "i" global variable, which is an unexpected side effect.

Replacing
:: Code ::
for ( i = 0; i < a_all_cookies.length; i++ )
with
:: Code ::
for ( var i = 0; i < a_all_cookies.length; i++ )
fixes this.
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
Calling this a bug is stretching it a bit, more of a wish list item, but I added an explicit var i = ''; declaration anyway since it is always good practice to declare and localize variables, though in this case there was no actual error in the script in terms of its own operation.
Back to top
ErwanLegrand
Status: New User - Welcome
Joined: 05 Nov 2009
Posts: 2
Location: Earth
Reply Quote
I guess it all depends whether or not you consider this function is meant to be used in larger programs. Call this function in a loop writen in the same style (with a global "i" as loop index) and you end up with a mess.
Back to top
Pls, where is the original code that this Post fixes?
vmars316
Status: New User - Welcome
Joined: 12 May 2010
Posts: 1
Location: Brownsville, Texas 78526
Reply Quote
My first shot at cookies:

Pls, where is the original code that this Post fixes?

Thanks...vmars316
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
click on the link in the first post.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours