Skip to content

Commit

Permalink
convert to utf8 string
Browse files Browse the repository at this point in the history
  • Loading branch information
hotchpotch committed Apr 19, 2011
1 parent 46a842f commit 246597c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 14 additions & 2 deletions spec/integration/session_spec.rb
@@ -1,3 +1,5 @@
# -*- encoding: UTF-8 -*-

require 'spec_helper'
require 'capybara-webkit'

Expand Down Expand Up @@ -50,18 +52,28 @@
body = <<-HTML
<html><body>
<strong>Hello</strong>
<span>UTF8文字列</span>
</body></html>
HTML
[200,
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
{ 'Content-Type' => 'text/html; charset=UTF-8', 'Content-Length' => body.length.to_s },
[body]]
end
end

it "inspects nodes" do
before do
subject.visit("/")
end

it "inspects nodes" do
subject.all(:xpath, "//strong").first.inspect.should include("strong")
end

it "utf8 string" do
utf8str = subject.all(:xpath, "//span").first.text
utf8str = utf8str.dup.force_encoding('UTF-8') if Kernel.const_defined?(:Encoding) # for Ruby 1.9
utf8str.should eq('UTF8文字列')
end
end
end

Expand Down
5 changes: 3 additions & 2 deletions src/Connection.cpp
Expand Up @@ -123,8 +123,9 @@ void Connection::writeResponse(bool success, QString &response) {
else
m_socket->write("failure\n");

QString responseLength = QString::number(response.size()) + "\n";
QByteArray response_utf8 = response.toUtf8();
QString responseLength = QString::number(response_utf8.size()) + "\n";
m_socket->write(responseLength.toAscii());
m_socket->write(response.toAscii());
m_socket->write(response_utf8);
}

0 comments on commit 246597c

Please sign in to comment.