From e72b48fc26549c81251c202c864cebe112042b4a Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Mon, 1 Apr 2013 23:08:11 -0400 Subject: [PATCH] Don't cast raw frame content to QString The conversion is lossy and drops non-ASCII characters. Fixes #503. --- spec/driver_spec.rb | 18 ++++++++++++++++++ src/body.cpp | 7 ++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index d4a966d..4816143 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -301,6 +301,24 @@ describe Capybara::Webkit::Driver do end end + context "binary content app" do + let(:driver) do + driver_for_app do + get '/' do + headers 'Content-Type' => 'application/octet-stream' + "Hello\xFF\xFF\xFF\xFFWorld" + end + end + end + + before { visit("/") } + + it "should return the binary content" do + src = driver.html.force_encoding('binary') + src.should == "Hello\xFF\xFF\xFF\xFFWorld".force_encoding('binary') + end + end + context "hello app" do let(:driver) do driver_for_html(<<-HTML) diff --git a/src/body.cpp b/src/body.cpp index 95b4e95..1286c65 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -6,11 +6,8 @@ Body::Body(WebPageManager *manager, QStringList &arguments, QObject *parent) : S } void Body::start() { - QString result; if (page()->contentType().contains("html")) - result = page()->currentFrame()->toHtml(); + finish(true, page()->currentFrame()->toHtml()); else - result = page()->body(); - - finish(true, result); + finish(true, page()->body()); }