You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matt Sergeant <ma...@sergeant.org> on 2000/02/22 17:36:55 UTC
Apache::Cookie bug
If you set a cookie that is an arrayref, which is really a hashref, with
undef in some of the values, you don't get those undef elements back:
Apache::Cookie->new(
$r,
-name => 'EXAMPLE',
-value => {key1 => 'val', key2 => undef},
-expires => '+6M',
-path => '/',
)->bake;
The cookie gets set properly to:
EXAMPLE=key1&val&key2&
but upon retrieval the array you get back is:
('key1','val','key2')
rather than the correct:
('key1', 'val', 'key2', undef)
Causing errors that say "Odd number of elements in hash assignment".
For now I guess I'll just fill in 0's rather than undefs.
--
<Matt/>
Details: FastNet Software Ltd - XML, Perl, Databases.
Tagline: High Performance Web Solutions
Web Sites: http://come.to/fastnet http://sergeant.org
Available for Consultancy, Contracts and Training.
Re: Apache::Cookie bug
Posted by Doug MacEachern <do...@pobox.com>.
On Tue, 22 Feb 2000, Matt Sergeant wrote:
> If you set a cookie that is an arrayref, which is really a hashref, with
> undef in some of the values, you don't get those undef elements back:
>
> Apache::Cookie->new(
> $r,
> -name => 'EXAMPLE',
> -value => {key1 => 'val', key2 => undef},
> -expires => '+6M',
> -path => '/',
> )->bake;
>
> The cookie gets set properly to:
>
> EXAMPLE=key1&val&key2&
>
> but upon retrieval the array you get back is:
>
> ('key1','val','key2')
>
> rather than the correct:
>
> ('key1', 'val', 'key2', undef)
>
> Causing errors that say "Odd number of elements in hash assignment".
this should fix it (untested):
--- Cookie.xs 1999/06/29 01:49:16 1.2
+++ Cookie.xs 2000/03/01 07:12:45
@@ -75,7 +75,9 @@
(void)hv_iterinit(hv);
while ((sv = hv_iternextsv(hv, &value, &len))) {
(void)ApacheCookie_attr(RETVAL, key, value);
- (void)ApacheCookie_attr(RETVAL, key, SvPV(sv,na));
+ (void)ApacheCookie_attr(RETVAL, key,
+ sv == &sv_undef ?
+ "" : SvPV(sv,na));
}
}
else {