From 1cd98a092feb1891f81f21cd40a0a56bf4876296 Mon Sep 17 00:00:00 2001
From: Gaute Hope <eg@gaute.vetsj.com>
Date: Thu, 9 Sep 2010 13:48:49 +0200
Subject: [PATCH] Force UTF-8 on label and contact completion

Fix issue 36, by forcing UTF-8 encoding on string that will be matched.

Only if the force_encoding method is available to maintain 1.8
compatability.

There is likely to still be a few other places where the equivilent of
this bug still exists.

Also force encoding on label search completion

UTF-8 label completion: Convert existing labels
---
 lib/sup/buffer.rb |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
index 04bbdcf..f3cfb8a 100644
--- a/lib/sup/buffer.rb
+++ b/lib/sup/buffer.rb
@@ -453,6 +453,7 @@ EOS
 
   def ask_with_completions domain, question, completions, default=nil
     ask domain, question, default do |s|
+      s.force_encoding 'UTF-8' if s.methods.include?(:encoding)
       completions.select { |x| x =~ /^#{Regexp::escape s}/i }.map { |x| [x, x] }
     end
   end
@@ -469,6 +470,8 @@ EOS
           raise "william screwed up completion: #{partial.inspect}"
         end
 
+      prefix.force_encoding 'UTF-8' if prefix.methods.include?(:encoding)
+      target.force_encoding 'UTF-8' if target.methods.include?(:encoding)
       completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] }
     end
   end
@@ -477,6 +480,7 @@ EOS
     ask domain, question, default do |partial|
       prefix, target = partial.split_on_commas_with_remainder
       target ||= prefix.pop || ""
+      target.force_encoding 'UTF-8' if target.methods.include?(:encoding)
       prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ")
       completions.select { |x| x =~ /^#{Regexp::escape target}/i }.sort_by { |c| [ContactManager.contact_for(c) ? 0 : 1, c] }.map { |x| [prefix + x, x] }
     end
-- 
1.7.3

