Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7978

Show
Ignore:
Timestamp:
10/20/07 17:30:01 (11 months ago)
Author:
rick
Message:

Ensure that cookies handle array values correctly. Closes #9937 [queso]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r7976 r7978  
    11*SVN* 
     2 
     3* Ensure that cookies handle array values correctly.  Closes #9937 [queso] 
    24 
    35* Make sure resource routes don't clash with internal helpers like javascript_path, image_path etc.  #9928 [gbuesing] 
  • trunk/actionpack/lib/action_controller/cookies.rb

    r7525 r7978  
    4545    # (for simple name/value cookies without options). 
    4646    def [](name) 
    47       @cookies[name.to_s].value.first if @cookies[name.to_s] && @cookies[name.to_s].respond_to?(:value) 
     47      cookie = @cookies[name.to_s] 
     48      if cookie && cookie.respond_to?(:value) 
     49        cookie.size > 1 ? cookie.value : cookie.value.to_s 
     50      end  
    4851    end 
    4952 
  • trunk/actionpack/test/controller/cookie_test.rb

    r7666 r7978  
    1919      cookies["login"]     = "XJ-122" 
    2020    end 
    21  
     21     
    2222    def access_frozen_cookies 
    2323      cookies["will"] = "work" 
     
    9393  end 
    9494 
     95  def test_cookiejar_accessor_with_array_value 
     96    a = %w{1 2 3} 
     97    @request.cookies["pages"] = CGI::Cookie.new("name" => "pages", "value" => a, "expires" => Time.local(2025, 10, 10)) 
     98    @controller.request = @request 
     99    jar = ActionController::CookieJar.new(@controller) 
     100    assert_equal a, jar["pages"] 
     101  end 
     102   
    95103  def test_delete_cookie_with_path 
    96104    get :delete_cookie_with_path