Subject: Re: [sup-devel] Another UTF-8 exception: edit-message-mode.rb

From: Hamish Downer <[email-masked]>
Date: Mon, 20 Jun 2011 22:55:59 +0100

Excerpts from Gaute Hope's message of Tue May 31 08:57:39 +0100 2011:
> ran into another UTF-8 exception in edit-message-mode, I don't know
> exactly what is causing it - but could be UTF-8 chars in some of the
> keywords that are sanitized.
> 
> And a patch:
> 0001-Fix-UTF-8-exception-in-santizing-body.patch

OK, I've had a look at this. From the patch:

   def sanitize_body body
+    body.force_encoding 'UTF-8' if body.methods.include?(:encoding)
     body.gsub(/^From /, ">From ")
   end
 
I'm not convinced that force_encoding is the best thing to use here. I
would expect it to be better to use encode! in most cases.
force_encoding does not change the string at all, only the encoding,
while encode! will change the string to a new string that may have
different underlying bytes.

Instead of the above patch could you try:

   def sanitize_body body
+    body.encode! 'UTF-8' if body.methods.include?(:encoding)
     body.gsub(/^From /, ">From ")
   end

and see if that also fixes your bug?

Hamish Downer
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Gaute Hope <[email-masked]>
Date: Tue, 31 May 2011 09:57:39 +0200

Hi,

Anyway, exception:
--- ArgumentError from thread: main
invalid byte sequence in UTF-8
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/modes/edit-message-mode.rb:498:in `gsub'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/modes/edit-message-mode.rb:498:in `sanitize_body'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/modes/edit-message-mode.rb:373:in `block in send_message'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/mbox.rb:114:in `block in store_message'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/mbox.rb:111:in `open'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/mbox.rb:111:in `store_message'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/sent.rb:28:in `write_sent_message'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/util.rb:618:in `method_missing'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/modes/edit-message-mode.rb:373:in `send_message'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/mode.rb:59:in `handle_input'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/lib/sup/buffer.rb:277:in `handle_input'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/bin/sup:271:in `<module:Redwood>'
/home/gaute/.gem/ruby/1.9.1/gems/sup-999/bin/sup:80:in `<top (required)>'
/home/gaute/.gem/ruby/1.9.1/bin/sup:19:in `load'
/home/gaute/.gem/ruby/1.9.1/bin/sup:19:in `<main>'

And a patch:

Best regards,
Gaute

---

From: Gaute Hope <[email-masked]>
Date: Thu, 09 Jun 2011 13:30:30 +0200

> 0001-Fix-UTF-8-exception-in-santizing-body.patch

*bump*

Any comments on this or on whether it will be included?

Cheers,
Gaute