gimite / web-socket-ruby

HTML5 Web Socket server/client implementation in Ruby
375 stars 71 forks source link

lib/web_socket.rb:344:in `fnmatch': can't convert nil into String (TypeError) #5

Closed laftho closed 14 years ago

laftho commented 14 years ago

In the case of testing locally, just accessing an HTML file directly via the browser, the origin will be nil therefore the domain will be nil via the origin_to_domain method resulting in an invalid check with File.fnmatch(d, domain).

method:

def accepted_origin?(origin) domain = origin_to_domain(origin) return @accepted_domains.any?(){ |d| File.fnmatch(d, domain) } end

Original faulty line 344:

return @accepted_domains.any?(){ |d| File.fnmatch(d, domain) }

Potential fix:

return @accepted_domains.any?(){ |d| (domain != nil ? File.fnmatch(d, domain) : true) }

gimite commented 14 years ago

Thanks for the report. Fixed with http://github.com/gimite/web-socket-ruby/commit/abbbe0b674cb71fb7658b2792b4ccc5d98e6f0cd

Note that, with my change, you need :accepted_domains = ["null"] or :accepted_domains = ["*"] to accept connection from local file.