Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* Another UTF-8 exception: edit-message-mode.rb
@ 2011-05-31  7:57 Gaute Hope
  2011-06-09 11:30 ` Gaute Hope
  2011-06-20 21:55 ` [sup-devel] " Hamish Downer
  0 siblings, 2 replies; 3+ messages in thread
From: Gaute Hope @ 2011-05-31  7:57 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 1549 bytes --]

Hi,

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.

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:
0001-Fix-UTF-8-exception-in-santizing-body.patch

Best regards,
Gaute

[-- Attachment #2: 0001-Fix-UTF-8-exception-in-santizing-body.patch --]
[-- Type: application/octet-stream, Size: 693 bytes --]

From f2db17f5ead96221a2f34451b083576df089102d Mon Sep 17 00:00:00 2001
From: Gaute Hope <eg@gaute.vetsj.com>
Date: Tue, 31 May 2011 09:53:19 +0200
Subject: [PATCH] Fix UTF-8 exception in santizing body

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

diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index a374197..2251eba 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -541,6 +541,7 @@ protected
 private
 
   def sanitize_body body
+    body.force_encoding 'UTF-8' if body.methods.include?(:encoding)
     body.gsub(/^From /, ">From ")
   end
 
-- 
1.7.5.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Another UTF-8 exception: edit-message-mode.rb
  2011-05-31  7:57 Another UTF-8 exception: edit-message-mode.rb Gaute Hope
@ 2011-06-09 11:30 ` Gaute Hope
  2011-06-20 21:55 ` [sup-devel] " Hamish Downer
  1 sibling, 0 replies; 3+ messages in thread
From: Gaute Hope @ 2011-06-09 11:30 UTC (permalink / raw)
  To: sup-devel

Excerpts from Gaute Hope's message of 2011-05-31 09:57:39 +0200:
> And a patch:
> 0001-Fix-UTF-8-exception-in-santizing-body.patch

*bump*

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

Cheers,
Gaute


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [sup-devel] Another UTF-8 exception: edit-message-mode.rb
  2011-05-31  7:57 Another UTF-8 exception: edit-message-mode.rb Gaute Hope
  2011-06-09 11:30 ` Gaute Hope
@ 2011-06-20 21:55 ` Hamish Downer
  1 sibling, 0 replies; 3+ messages in thread
From: Hamish Downer @ 2011-06-20 21:55 UTC (permalink / raw)
  To: sup-devel

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
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-20 21:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-31  7:57 Another UTF-8 exception: edit-message-mode.rb Gaute Hope
2011-06-09 11:30 ` Gaute Hope
2011-06-20 21:55 ` [sup-devel] " Hamish Downer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox