diff --git a/lib/shrimp/phantom.rb b/lib/shrimp/phantom.rb index 9b689ff..23c916b 100644 --- a/lib/shrimp/phantom.rb +++ b/lib/shrimp/phantom.rb @@ -95,7 +95,7 @@ def cmd def initialize(url_or_file, options = { }, cookies={ }, outfile = nil) @source = Source.new(url_or_file) @options = Shrimp.configuration.default_options.merge(options) - @cookies = cookies + @cookies = escape_cookies(cookies) @outfile = File.expand_path(outfile) if outfile raise NoExecutableError.new unless File.exists?(Shrimp.configuration.phantomjs) end @@ -149,5 +149,9 @@ def dump_cookies json = @cookies.inject([]) { |a, (k, v)| a.push({ :name => k, :value => v, :domain => host }); a }.to_json File.open("#{options[:tmpdir]}/#{rand}.cookies", 'w') { |f| f.puts json; f }.path end + + def escape_cookies(cookies) + Hash[cookies.map { |key, value| [key, CGI.escape(value)] }] + end end end