[Webkit-unassigned] [Bug 26791] [Gtk] Paste of rich text from firefox results garbled markup

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jun 30 03:34:53 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=26791





------- Comment #6 from jhuangjiahua at gmail.com  2009-06-30 03:34 PDT -------
(In reply to comment #5)
> (From update of attachment 32013 [review])
> Won't this still end up with the UTF16 BOM char pasted into your web page? 
> WebKit is smart enough to ignore BOMs in the middle of pages, but it seems
> silly to paste them in.
> 

Hi, Eric,

The problem of garbled is not on the BOMs,
it is that String::fromUTF8()

the code in WebCore/platform/text/String.cpp:
> String String::fromUTF8(const char* string, size_t size)
> 
> String String::fromUTF8(const char* string, size_t size)
> {
>     if (!string)
>         return String();
>     return UTF8Encoding().decode(string, size);
> }

the string must be legal UTF-8 encoding chars,
and the size must be right length.

When gtk.Clipbord put a UTF-16 data,
the string is not legal UTF-8 encoding chars but UChar,
and the length muse be Halved.

So, the old code will wrong for encoding (multiple decoding) and size,
the wrong of size (double the right length) will make markups confused.



So, I maked this changes:
> -        String html = String::fromUTF8(reinterpret_cast<gchar*>(data->data), data->length * data->format / 8);
> +        String html;
> +        if (reinterpret_cast<UChar*>(data->data)[0] == 0xFEFF
> +                || reinterpret_cast<UChar*>(data->data)[0] == 0xFFFE)
> +            html = String(reinterpret_cast<UChar*>(data->data), data->length * data->format / 16);
> +        else
> +            html = String::fromUTF8(reinterpret_cast<gchar*>(data->data), data->length * data->format / 8);

Let it use String::String() instead of String::fromUTF8
when gtk.Clipbord put a UTF-16 data (BOMs used to discern)


-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list