Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"[]= called on nil object" on @jar[normal_domain][cookie.path][cookie.name] = cookie #3

Closed
naofumi opened this issue Jul 9, 2009 · 1 comment

Comments

@naofumi
Copy link

naofumi commented Jul 9, 2009

On the June 24th commit, cookie_jar.rb file. http://github.com/tenderlove/mechanize/blob/0cb78c906ea339e16829636be47fe35b5dc8be6f/lib/www/mechanize/cookie_jar.rb

On the #add method
def add(uri, cookie)
return unless uri.host =~ /#{CookieJar.strip_port(cookie.domain)}$/i

    normal_domain = cookie.domain.downcase

    unless @jar.has_key?(normal_domain)
      @jar[normal_domain] = Hash.new { |h,k| h[k] = {} }
    end

    @jar[normal_domain][cookie.path][cookie.name] = cookie
    cleanup
    cookie
  end

I sometimes get an error on
@jar[normal_domain][cookie.path][cookie.name] = cookie
complaining about "[]= called on nil object".

I suspect that when a cookie_jar is loaded from YAML, the default value for @jar[normal_domain] is not being correctly set. I'm currently adding
@jar[normal_domain][cookie.path] ||= {}
@jar[normal_domain][cookie.path][cookie.name] = cookie

@tenderlove
Copy link
Member

fixing default values used on unserialized cookie jars. closed by a97e92b

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants