You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@whimsical.apache.org by sebb <se...@gmail.com> on 2017/09/12 16:03:09 UTC

Re: [whimsy] branch master updated: don't die if the encoding is unknown

On 12 September 2017 at 15:53,  <ru...@apache.org> wrote:
> This is an automated email from the ASF dual-hosted git repository.
>
> rubys pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/whimsy.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
>      new 9d5e3c6  don't die if the encoding is unknown
> 9d5e3c6 is described below
>
> commit 9d5e3c6aa3a9f0aef8908121a5eeed102521df4e
> Author: Sam Ruby <ru...@intertwingly.net>
> AuthorDate: Tue Sep 12 10:53:24 2017 -0400
>
>     don't die if the encoding is unknown
> ---
>  www/secretary/workbench/views/body.html.rb | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/www/secretary/workbench/views/body.html.rb b/www/secretary/workbench/views/body.html.rb
> index 204c02d..e562c9d 100644
> --- a/www/secretary/workbench/views/body.html.rb
> +++ b/www/secretary/workbench/views/body.html.rb
> @@ -43,7 +43,7 @@ _html do
>        body = @message.html_part.body.to_s
>
>        if body.to_s.encoding == Encoding::BINARY and @message.html_part.charset
> -        body.force_encoding(@message.html_part.charset)
> +        body.force_encoding(@message.html_part.charset) rescue nil

Just wondering if it would be worth trying other charsets if  the
explicit one fails?

e.g. try UTF-8 or IS0-8859-1 if the other was provided.
Also could try those even if no charset was provided.

>        end
>
>        nodes = _{body.encode('utf-8', invalid: :replace, undef: :replace)}
> @@ -54,7 +54,7 @@ _html do
>      body = @message.text_part.body.to_s
>
>      if body.to_s.encoding == Encoding::BINARY and @message.text_part.charset
> -      body.force_encoding(@message.text_part.charset)
> +      body.force_encoding(@message.text_part.charset) rescue nil
>      end
>
>      _pre.bg_info body.encode('utf-8', invalid: :replace, undef: :replace)
>
> --
> To stop receiving notification emails like this one, please contact
> ['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].

Re: [whimsy] branch master updated: don't die if the encoding is unknown

Posted by sebb <se...@gmail.com>.
On 12 September 2017 at 18:06, Sam Ruby <ru...@intertwingly.net> wrote:
> On Tue, Sep 12, 2017 at 12:03 PM, sebb <se...@gmail.com> wrote:
>> On 12 September 2017 at 15:53,  <ru...@apache.org> wrote:
>>> This is an automated email from the ASF dual-hosted git repository.
>>>
>>> rubys pushed a commit to branch master
>>> in repository https://gitbox.apache.org/repos/asf/whimsy.git
>>>
>>>
>>> The following commit(s) were added to refs/heads/master by this push:
>>>      new 9d5e3c6  don't die if the encoding is unknown
>>> 9d5e3c6 is described below
>>>
>>> commit 9d5e3c6aa3a9f0aef8908121a5eeed102521df4e
>>> Author: Sam Ruby <ru...@intertwingly.net>
>>> AuthorDate: Tue Sep 12 10:53:24 2017 -0400
>>>
>>>     don't die if the encoding is unknown
>>> ---
>>>  www/secretary/workbench/views/body.html.rb | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/www/secretary/workbench/views/body.html.rb b/www/secretary/workbench/views/body.html.rb
>>> index 204c02d..e562c9d 100644
>>> --- a/www/secretary/workbench/views/body.html.rb
>>> +++ b/www/secretary/workbench/views/body.html.rb
>>> @@ -43,7 +43,7 @@ _html do
>>>        body = @message.html_part.body.to_s
>>>
>>>        if body.to_s.encoding == Encoding::BINARY and @message.html_part.charset
>>> -        body.force_encoding(@message.html_part.charset)
>>> +        body.force_encoding(@message.html_part.charset) rescue nil
>>
>> Just wondering if it would be worth trying other charsets if  the
>> explicit one fails?
>>
>> e.g. try UTF-8 or IS0-8859-1 if the other was provided.
>> Also could try those even if no charset was provided.
>
> The charset that triggered the error: "ks_c_5601-1987".  Apparently,
> treating it as EUC-KR would mostly be OK.  I have no earthly clue how
> many charsets could benefit from such a mapping, but this seems rare
> to me.  Perhaps Craig can comment.
>
> The "fix" I pushed, effectively treats it as ASCII, with non-ASCII
> characters replaced with U+FFFD.  This at least made the subject email
> in question readable.

I see. Doesn't sound like it could be improved.

Sorry, my bad, I should have checked the full code rather than
assuming how it behaved from the snippet.


> - Sam Ruby
>
>>>        end
>>>
>>>        nodes = _{body.encode('utf-8', invalid: :replace, undef: :replace)}
>>> @@ -54,7 +54,7 @@ _html do
>>>      body = @message.text_part.body.to_s
>>>
>>>      if body.to_s.encoding == Encoding::BINARY and @message.text_part.charset
>>> -      body.force_encoding(@message.text_part.charset)
>>> +      body.force_encoding(@message.text_part.charset) rescue nil
>>>      end
>>>
>>>      _pre.bg_info body.encode('utf-8', invalid: :replace, undef: :replace)
>>>
>>> --
>>> To stop receiving notification emails like this one, please contact
>>> ['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].

Re: [whimsy] branch master updated: don't die if the encoding is unknown

Posted by Sam Ruby <ru...@intertwingly.net>.
On Tue, Sep 12, 2017 at 12:03 PM, sebb <se...@gmail.com> wrote:
> On 12 September 2017 at 15:53,  <ru...@apache.org> wrote:
>> This is an automated email from the ASF dual-hosted git repository.
>>
>> rubys pushed a commit to branch master
>> in repository https://gitbox.apache.org/repos/asf/whimsy.git
>>
>>
>> The following commit(s) were added to refs/heads/master by this push:
>>      new 9d5e3c6  don't die if the encoding is unknown
>> 9d5e3c6 is described below
>>
>> commit 9d5e3c6aa3a9f0aef8908121a5eeed102521df4e
>> Author: Sam Ruby <ru...@intertwingly.net>
>> AuthorDate: Tue Sep 12 10:53:24 2017 -0400
>>
>>     don't die if the encoding is unknown
>> ---
>>  www/secretary/workbench/views/body.html.rb | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/www/secretary/workbench/views/body.html.rb b/www/secretary/workbench/views/body.html.rb
>> index 204c02d..e562c9d 100644
>> --- a/www/secretary/workbench/views/body.html.rb
>> +++ b/www/secretary/workbench/views/body.html.rb
>> @@ -43,7 +43,7 @@ _html do
>>        body = @message.html_part.body.to_s
>>
>>        if body.to_s.encoding == Encoding::BINARY and @message.html_part.charset
>> -        body.force_encoding(@message.html_part.charset)
>> +        body.force_encoding(@message.html_part.charset) rescue nil
>
> Just wondering if it would be worth trying other charsets if  the
> explicit one fails?
>
> e.g. try UTF-8 or IS0-8859-1 if the other was provided.
> Also could try those even if no charset was provided.

The charset that triggered the error: "ks_c_5601-1987".  Apparently,
treating it as EUC-KR would mostly be OK.  I have no earthly clue how
many charsets could benefit from such a mapping, but this seems rare
to me.  Perhaps Craig can comment.

The "fix" I pushed, effectively treats it as ASCII, with non-ASCII
characters replaced with U+FFFD.  This at least made the subject email
in question readable.

- Sam Ruby

>>        end
>>
>>        nodes = _{body.encode('utf-8', invalid: :replace, undef: :replace)}
>> @@ -54,7 +54,7 @@ _html do
>>      body = @message.text_part.body.to_s
>>
>>      if body.to_s.encoding == Encoding::BINARY and @message.text_part.charset
>> -      body.force_encoding(@message.text_part.charset)
>> +      body.force_encoding(@message.text_part.charset) rescue nil
>>      end
>>
>>      _pre.bg_info body.encode('utf-8', invalid: :replace, undef: :replace)
>>
>> --
>> To stop receiving notification emails like this one, please contact
>> ['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].