Subject: Re: [sup-devel] Bug: UTF-8 error when sending messages

From: Tero Tilus <[email-masked]>
Date: Sat, 29 Jan 2011 20:17:36 +0200

Adeel Ahmad Khan, 2011-01-29 05:11:
>     invalid byte sequence in UTF-8
...
> I am using a nearly fresh installation of Sup 0.12.1 with Ruby
> 1.9.2p136.  I have LOCALE="en_US.UTF-8".

Both the errors were from regex matches against message body.  Somehow
your editor doesn't know your locale or is not obeying it.  As a
result non-utf8 stuff gets saved to disk and sup gets confused.

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Gaute Hope <[email-masked]>
Date: Sun, 30 Jan 2011 16:58:31 +0100

Excerpts from Adeel Ahmad Khan's message of 2011-01-29 04:11:40 +0100:
> When sending a message containing certain characters, like guillemets
> <http://en.wikipedia.org/wiki/Guillemets>, I experiencing the following error.
> 
>     --- ArgumentError from thread: main
>     /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/modes/edit-message-mode.rb:497:in `block in mentions_attachments?'

Could you try if this patch fixes it (or just edit the lines manually) ?

- Gaute

>From 67a8777875091da6ae57c762f18254509f418a46 Mon Sep 17 00:00:00 2001
From: Gaute Hope <[email-masked]>
Date: Sun, 30 Jan 2011 16:57:15 +0100
Subject: [PATCH] Attempt to handle encoding errors when searching for attachment string

---
 lib/sup/modes/edit-message-mode.rb |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index 734a879..8517011 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -494,7 +494,10 @@ private
     if HookManager.enabled? "mentions-attachments"
       HookManager.run "mentions-attachments", :header => @header, :body => @body
     else
-      @body.any? {  |l| l =~ /^[^>]/ && l =~ /\battach(ment|ed|ing|)\b/i }
+      @body.any? {  |l|
+        l.force_encoding 'UTF-8' if l.methods.include?(:encoding)
+        l =~ /^[^>]/ && l =~ /\battach(ment|ed|ing|)\b/i
+      }
     end
   end
 
-- 
1.7.3.5

---

From: Adeel Ahmad Khan <[email-masked]>
Date: Fri, 28 Jan 2011 22:11:40 -0500

--- ArgumentError from thread: main
    invalid byte sequence in UTF-8
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/modes/edit-message-mode.rb:497:in `block in mentions_attachments?'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/modes/edit-message-mode.rb:497:in `each'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/modes/edit-message-mode.rb:497:in `any?'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/modes/edit-message-mode.rb:497:in `mentions_attachments?'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/modes/edit-message-mode.rb:339:in `send_message'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/mode.rb:59:in `handle_input'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/buffer.rb:277:in `handle_input'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/bin/sup:260:in `<module:Redwood>'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/bin/sup:69:in `<top (required)>'
    /usr/bin/sup:19:in `load'
    /usr/bin/sup:19:in `<main>'

After setting :confirm_no_attachments and :confirm_top_posting to false, I get
the following error instead.

    --- ArgumentError from thread: main
    invalid byte sequence in UTF-8
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/modes/edit-message-mode.rb:389:in `build_message'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/modes/edit-message-mode.rb:354:in `send_message'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/mode.rb:59:in `handle_input'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/lib/sup/buffer.rb:277:in `handle_input'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/bin/sup:260:in `<module:Redwood>'
    /usr/lib/ruby/gems/1.9.1/gems/sup-0.12.1/bin/sup:69:in `<top (required)>'
    /usr/bin/sup:19:in `load'
    /usr/bin/sup:19:in `<main>'

I am using a nearly fresh installation of Sup 0.12.1 with Ruby 1.9.2p136.  I
have LOCALE="en_US.UTF-8".

Adeel