ruby / cgi

CGI is a large class, providing several categories of methods, many of which are mixed in from other modules.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Since 2.7.7 CGI::Cookie raises ArgumentError when cookie domains is prefixed with a dot

cpinto opened this issue · comments

The rspec tests of our Rails app started failing with an ArgumentError after upgrading to 2.7.7. On inspection, the issue seems to be caused by CGI::Cookie.domain=:

def domain=(str)
      if str and ((str = str.b).bytesize > 255 or !DOMAIN_VALUE_RE.match?(str))
        raise ArgumentError, "invalid domain: #{str.dump}"
      end
      @domain = str
    end

Setting a breakpoint:

0> str
=> ".example.com"

0> DOMAIN_VALUE_RE
=> /\A(?(?!-)[-A-Za-z0-9]+(?<!-))(?:.\g)*\z/

0> DOMAIN_VALUE_RE.match?(str)
=> false

0> DOMAIN_VALUE_RE.match?('example.com')
=> true

closing as there's already a PR in the works

PR #29 was merged