From 246597c36b6d218f640c88aeb22d39b84f892f1e Mon Sep 17 00:00:00 2001 From: Yuichi Tateno Date: Tue, 19 Apr 2011 18:07:42 +0900 Subject: [PATCH] convert to utf8 string --- spec/integration/session_spec.rb | 16 ++++++++++++++-- src/Connection.cpp | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 57479bf..eec0ab3 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -1,3 +1,5 @@ +# -*- encoding: UTF-8 -*- + require 'spec_helper' require 'capybara-webkit' @@ -50,18 +52,28 @@ describe Capybara::Session do body = <<-HTML Hello + UTF8文字列 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 diff --git a/src/Connection.cpp b/src/Connection.cpp index 91482ba..69753fe 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -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); }