Status: Unconfirmed
Owner: ----
Labels: Type-Bug Pri-2 OS-All Area-Misc

New issue 27258 by Adam.Walling: Fails to paste HTML Format text from  
clipboard if missing <!--StartFragment--> <!--EndFragment--> tags (Windows)
http://code.google.com/p/chromium/issues/detail?id=27258

Chrome Version       : 31550
URLs (if applicable) : Any (though mostly tested using GMail)
Other browsers tested:
   Add OK or FAIL after other browsers where you have tested this issue:
      Safari 4: ?
   Firefox 3.x: OK
          IE 7: OK
          IE 8: OK

What steps will reproduce the problem?
1. Copy HTML to clipboard without using <!--StartFragment--> and <!--
EndFragment--> tags.
2. Try to paste HTML into a rich text field, such as composing an e-mail in
GMail.
3. Profit.

What is the expected result?

The styled text should be pasted into the rich text field.

What happens instead?

It will paste nothing, as in blank. It does try to paste, and will
overwrite anything that is selected, but with blank (not even a space).

Please provide any additional information below. Attach a screenshot if
possible.

The "HTML Format" clipboard format is just text with a special header. You
can see it defined here: http://msdn.microsoft.com/en-
us/library/ms649015(VS.85).aspx

It provides the ability to identify fragments and selections within an HTML
document (Context).

This example works correctly in chrome, assuming CRLF line terminators
(\r\n) to keep the byte count correct:

Version:0.9
StartHTML:00000145
EndHTML:00000337
StartFragment:00000240
EndFragment:00000305
StartSelection:00000240
EndSelection:00000305
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"><html><body><!--StartFragment--><a
href="http://code.google.com/p/chromium/";>Chromium Project</a><!--
EndFragment--></body></html>

However this does not:

Version:0.9
StartHTML:00000145
EndHTML:00000299
StartFragment:00000220
EndFragment:00000285
StartSelection:00000220
EndSelection:00000285
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"><html><body><a
href="http://code.google.com/p/chromium/";>Chromium
Project</a></body></html>

The only difference is the first example uses the <!--StartFragment--> and
<!--EndFragment--> comments. The specifications state:

"The fragment should be preceded and followed by the HTML comments <!--
StartFragment--> and <!--EndFragment--> (no space allowed between the !--
and the text) to conveniently indicate where the fragment starts and ends.
Thus the start and end of the fragment are indicated by the presence of
these comments and by StartFragment and EndFragment byte counts in the
description. Tools are expected to produce this information. This
redundancy has been introduced to be able to rapidly find the start of the
fragment (from the byte count) and mark the position of the fragment
directly in the HTML tree."

However every other browser handles the absence of the tags properly. Most
applications will copy with these tags in place, however several
applications do not, hence how I found this bug. There appears to be some
example code for copying HTML to the clipboard distributed around the
internet which omits these comment tags. Considering that other browsers
can gracefully handle this situation, it seems that Chromium should also
acquiesce as well, since from the end-user's viewpoint this appears to be a
bug in Chromium rather than in their software. In the end, the inclusion of
the <!--StartFragment--> and <!--EndFragment--> is optional from a de facto
standpoint.

That said, this is a very minor issue, but also one that is probably
underreported.

Here is C/C++ code fragment to paste these examples into the clipboard:

// assume hwnd is your hwnd, and sz is your ASCII html string. If using my
examples, remember to use \r\n to keep the byte counts correct
OpenClipboard(hwnd);
EmptyClipboard();
HGLOBAL hglobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, strlen(sz)+1);
char* p = (char*)GlobalLock(hglobal);
strcpy(p, sz);
GlobalUnlock(hglobal);
SetClipboardData(RegisterClipboardFormat("HTML Format", hglobal);
CloseClipboard()

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

-- 
Automated mail from issue updates at http://crbug.com/
Subscription options: http://groups.google.com/group/chromium-bugs

Reply via email to