Permalink
Browse files

revert and more test

  • Loading branch information...
1 parent 8c13352 commit bc2e8c1bbe8480906412c26815c2090e72a8e659 @kazeburo committed Feb 26, 2014
Showing with 29 additions and 5 deletions.
  1. +22 −5 lib/Cookie/Baker/XS.xs
  2. +7 −0 t/01_basic.t
View
@@ -103,8 +103,8 @@ crush_cookie(cookie)
Newx(key, key_size, char);
src = (char *)SvPV(cookie,src_len);
prev = src;
- for ( i=0; i<=src_len; i++ ) {
- if ( i == src_len || src[i] == ';' || src[i] == ',' ) {
+ for ( i=0; i<src_len; i++ ) {
+ if ( src[i] == ';' || src[i] == ',' ) {
while ( prev[0] == ' ' ) {
prev++;
prev_s++;
@@ -122,9 +122,26 @@ crush_cookie(cookie)
url_decode_val(aTHX_ prev, p - prev + 1, la ), 0);
}
}
- if ( i+1 < src_len ) {
- prev = &src[i+1];
- prev_s = i + 1;
+ prev = &src[i+1];
+ prev_s = i + 1;
+ }
+ }
+ if ( i > prev_s ) {
+ while ( prev[0] == ' ' ) {
+ prev++;
+ prev_s++;
+ }
+ la = i - prev_s;
+ while ( prev[la-1] == ' ' ) {
+ --la;
+ }
+ p = memchr(prev, '=', i - prev_s);
+ if ( p != NULL ) {
+ renewmem(aTHX_ &key, &key_size, (p - prev)*3+1);
+ url_decode_key(prev, p - prev, key, &key_len);
+ if ( !hv_exists(hv, key, key_len) ) {
+ (void)hv_store(hv, key, key_len,
+ url_decode_val(aTHX_ prev, p - prev + 1, la ), 0);
}
}
}
View
@@ -8,6 +8,13 @@ my @tests = (
[ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar; YYY=0; YYY=3', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar', YYY => 0 }],
[ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar; YYY=0; YYY=3;', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar', YYY => 0 }],
[ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar ; YYY=0; YYY=3;', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar', YYY => 0 }],
+ [ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar ; YYY=0; YYY=3; ', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar', YYY => 0 }],
+ [ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar ; YYY', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar' }],
+ [ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar ; YYY;', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar' }],
+ [ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar ; YYY; ', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar' }],
+ [ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar ; YYY=', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar', YYY=>"" }],
+ [ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar ; YYY=;', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar', YYY=>"" }],
+ [ 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar ; YYY=; ', { Foo => 'Bar', Bar => 'Baz', XXX => 'Foo Bar',YYY=>"" }],
[ "Foo=Bar; $longkey=Bar", { Foo => 'Bar', $longkey => 'Bar'}],
[ "Foo=Bar; $longkey=Bar; Bar=Baz", { Foo => 'Bar', $longkey => 'Bar', 'Bar'=>'Baz'}],
[ '', {} ],

0 comments on commit bc2e8c1

Please sign in to comment.