[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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