Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339735 - HTML on Clipboard appears as raw HTML in TextEdit
Summary: HTML on Clipboard appears as raw HTML in TextEdit
Status: RESOLVED DUPLICATE of bug 330122
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.2   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-11 12:50 EST by Craig Reichenbach CLA
Modified: 2011-03-30 18:13 EDT (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Craig Reichenbach CLA 2011-03-11 12:50:02 EST
Build Identifier: 3.6.2

The snippet below takes a raw html string and sets it on the SWT Clipboard. When you paste this Clipboard into TextEdit, it displays the raw HTML string instead of rendering the HTML.  If on the other hand you display the same html in a browser (save the raw html to an html file an open with Firefox) copy and paste it into TextEdit, it will render the HTML.

Examining the HTML content in the Clipboard Viewer.app (utility previously available in the dev toolkit on Mac 10.5) shows that the clipboard contents are different for the "public.html" type.  The SWT generated clipboard contains a period char after ever char, while the browser generated clipboard does not.

:: SWT Clipboard html details ::
public.html
Apple HTML pasteboard type
public.utf16-plain-text
'utxt' (CorePasteboardFlavorType 0x7574784)
public.utf8-plain-text
NSStringPboardType
com.ibm.traditional-mac-plain-text
'TEXT' (CorePasteboardFlavorType 0x54455854)

268 bytes of public.html that I copied from Clipboard Viewer.app:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title></title>
  <meta name="Generator" content="Cocoa HTML Writer">
  <meta name="CocoaVersion" content="1038.35">
  <style type="text/css">
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco}
  </style>
</head>
<body>
<p class="p1">00000000:<span class="Apple-converted-space">  </span>3c 00 68 00 74 00 6d 00 6c 00<span class="Apple-converted-space">  </span>&lt;.h.t.m.l.</p>
<p class="p1">00000010:<span class="Apple-converted-space">  </span>3e 00 3c 00 68 00 65 00 61 00<span class="Apple-converted-space">  </span>&gt;.&lt;.h.e.a.</p>
<p class="p1">00000020:<span class="Apple-converted-space">  </span>64 00 3e 00 3c 00 2f 00 68 00<span class="Apple-converted-space">  </span>d.&gt;.&lt;./.h.</p>
<p class="p1">00000030:<span class="Apple-converted-space">  </span>65 00 61 00 64 00 3e 00 3c 00<span class="Apple-converted-space">  </span>e.a.d.&gt;.&lt;.</p>
<p class="p1">00000040:<span class="Apple-converted-space">  </span>62 00 6f 00 64 00 79 00 3e 00<span class="Apple-converted-space">  </span>b.o.d.y.&gt;.</p>
<p class="p1">00000050:<span class="Apple-converted-space">  </span>3c 00 64 00 69 00 76 00 20 00<span class="Apple-converted-space">  </span>&lt;.d.i.v. .</p>
<p class="p1">00000060:<span class="Apple-converted-space">  </span>69 00 64 00 3d 00 22 00 6c 00<span class="Apple-converted-space">  </span>i.d.=.".l.</p>
<p class="p1">00000070:<span class="Apple-converted-space">  </span>74 00 73 00 61 00 6d 00 70 00<span class="Apple-converted-space">  </span>t.s.a.m.p.</p>
<p class="p1">00000080:<span class="Apple-converted-space">  </span>6c 00 65 00 22 00 3e 00 54 00<span class="Apple-converted-space">  </span>l.e.".&gt;.T.</p>
<p class="p1">00000090:<span class="Apple-converted-space">  </span>68 00 69 00 73 00 20 00 69 00<span class="Apple-converted-space">  </span>h.i.s. .i.</p>
<p class="p1">00000100:<span class="Apple-converted-space">  </span>73 00 20 00 73 00 6f 00 6d 00<span class="Apple-converted-space">  </span>s. .s.o.m.</p>
<p class="p1">00000110:<span class="Apple-converted-space">  </span>65 00 20 00 3c 00 69 00 3e 00<span class="Apple-converted-space">  </span>e. .&lt;.i.&gt;.</p>
<p class="p1">00000120:<span class="Apple-converted-space">  </span>68 00 74 00 6d 00 6c 00 3c 00<span class="Apple-converted-space">  </span>h.t.m.l.&lt;.</p>
<p class="p1">00000130:<span class="Apple-converted-space">  </span>2f 00 69 00 3e 00 20 00 74 00<span class="Apple-converted-space">  </span>/.i.&gt;. .t.</p>
<p class="p1">00000140:<span class="Apple-converted-space">  </span>65 00 78 00 74 00 2e 00 20 00<span class="Apple-converted-space">  </span>e.x.t... .</p>
<p class="p1">00000150:<span class="Apple-converted-space">  </span>20 00 4d 00 79 00 20 00 70 00 <span class="Apple-converted-space">  </span>.M.y. .p.</p>
<p class="p1">00000160:<span class="Apple-converted-space">  </span>68 00 6f 00 6e 00 65 00 20 00<span class="Apple-converted-space">  </span>h.o.n.e. .</p>
<p class="p1">00000170:<span class="Apple-converted-space">  </span>6e 00 75 00 6d 00 62 00 65 00<span class="Apple-converted-space">  </span>n.u.m.b.e.</p>
<p class="p1">00000180:<span class="Apple-converted-space">  </span>72 00 20 00 69 00 73 00 20 00<span class="Apple-converted-space">  </span>r. .i.s. .</p>
<p class="p1">00000190:<span class="Apple-converted-space">  </span>3c 00 62 00 3e 00 32 00 33 00<span class="Apple-converted-space">  </span>&lt;.b.&gt;.2.3.</p>
<p class="p1">00000200:<span class="Apple-converted-space">  </span>34 00 2d 00 32 00 33 00 34 00<span class="Apple-converted-space">  </span>4.-.2.3.4.</p>
<p class="p1">00000210:<span class="Apple-converted-space">  </span>2d 00 32 00 33 00 34 00 32 00<span class="Apple-converted-space">  </span>-.2.3.4.2.</p>
<p class="p1">00000220:<span class="Apple-converted-space">  </span>3c 00 2f 00 62 00 3e 00 3c 00<span class="Apple-converted-space">  </span>&lt;./.b.&gt;.&lt;.</p>
<p class="p1">00000230:<span class="Apple-converted-space">  </span>2f 00 64 00 69 00 76 00 3e 00<span class="Apple-converted-space">  </span>/.d.i.v.&gt;.</p>
<p class="p1">00000240:<span class="Apple-converted-space">  </span>3c 00 2f 00 62 00 6f 00 64 00<span class="Apple-converted-space">  </span>&lt;./.b.o.d.</p>
<p class="p1">00000250:<span class="Apple-converted-space">  </span>79 00 3e 00 3c 00 2f 00 68 00<span class="Apple-converted-space">  </span>y.&gt;.&lt;./.h.</p>
<p class="p1">00000260:<span class="Apple-converted-space">  </span>74 00 6d 00 6c 00 3e 00<span class="Apple-converted-space">        </span>t.m.l.&gt;. <span class="Apple-converted-space"> </span></p>
</body>
</html>

::Firefox Clipboard html details::
public.html
Apple HTML pasteboard type
public.utf8-plain-text
NSStringPboardType

200 bytes of public.html I copied from Clipboard Viewer.app:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title></title>
  <meta name="Generator" content="Cocoa HTML Writer">
  <meta name="CocoaVersion" content="1038.35">
  <style type="text/css">
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco}
  </style>
</head>
<body>
<p class="p1">00000000:<span class="Apple-converted-space">  </span>3c 68 74 6d 6c 3e 3c 68 65 61<span class="Apple-converted-space">  </span>&lt;html&gt;&lt;hea</p>
<p class="p1">00000010:<span class="Apple-converted-space">  </span>64 3e 3c 6d 65 74 61 20 68 74<span class="Apple-converted-space">  </span>d&gt;&lt;meta ht</p>
<p class="p1">00000020:<span class="Apple-converted-space">  </span>74 70 2d 65 71 75 69 76 3d 22<span class="Apple-converted-space">  </span>tp-equiv="</p>
<p class="p1">00000030:<span class="Apple-converted-space">  </span>63 6f 6e 74 65 6e 74 2d 74 79<span class="Apple-converted-space">  </span>content-ty</p>
<p class="p1">00000040:<span class="Apple-converted-space">  </span>70 65 22 20 63 6f 6e 74 65 6e<span class="Apple-converted-space">  </span>pe" conten</p>
<p class="p1">00000050:<span class="Apple-converted-space">  </span>74 3d 22 74 65 78 74 2f 68 74<span class="Apple-converted-space">  </span>t="text/ht</p>
<p class="p1">00000060:<span class="Apple-converted-space">  </span>6d 6c 3b 20 63 68 61 72 73 65<span class="Apple-converted-space">  </span>ml; charse</p>
<p class="p1">00000070:<span class="Apple-converted-space">  </span>74 3d 75 74 66 2d 38 22 3e 3c<span class="Apple-converted-space">  </span>t=utf-8"&gt;&lt;</p>
<p class="p1">00000080:<span class="Apple-converted-space">  </span>2f 68 65 61 64 3e 3c 62 6f 64<span class="Apple-converted-space">  </span>/head&gt;&lt;bod</p>
<p class="p1">00000090:<span class="Apple-converted-space">  </span>79 3e 3c 64 69 76 20 69 64 3d<span class="Apple-converted-space">  </span>y&gt;&lt;div id=</p>
<p class="p1">00000100:<span class="Apple-converted-space">  </span>22 6c 74 73 61 6d 70 6c 65 22<span class="Apple-converted-space">  </span>"ltsample"</p>
<p class="p1">00000110:<span class="Apple-converted-space">  </span>3e 54 68 69 73 20 69 73 20 73<span class="Apple-converted-space">  </span>&gt;This is s</p>
<p class="p1">00000120:<span class="Apple-converted-space">  </span>6f 6d 65 20 3c 69 3e 68 74 6d<span class="Apple-converted-space">  </span>ome &lt;i&gt;htm</p>
<p class="p1">00000130:<span class="Apple-converted-space">  </span>6c 3c 2f 69 3e 20 74 65 78 74<span class="Apple-converted-space">  </span>l&lt;/i&gt; text</p>
<p class="p1">00000140:<span class="Apple-converted-space">  </span>2e 20 4d 79 20 70 68 6f 6e 65<span class="Apple-converted-space">  </span>. My phone</p>
<p class="p1">00000150:<span class="Apple-converted-space">  </span>20 6e 75 6d 62 65 72 20 69 73 <span class="Apple-converted-space">  </span>number is</p>
<p class="p1">00000160:<span class="Apple-converted-space">  </span>20 3c 62 3e 32 33 34 2d 32 33 <span class="Apple-converted-space">  </span>&lt;b&gt;234-23</p>
<p class="p1">00000170:<span class="Apple-converted-space">  </span>34 2d 32 33 34 32 3c 2f 62 3e<span class="Apple-converted-space">  </span>4-2342&lt;/b&gt;</p>
<p class="p1">00000180:<span class="Apple-converted-space">  </span>3c 2f 64 69 76 3e 3c 2f 62 6f<span class="Apple-converted-space">  </span>&lt;/div&gt;&lt;/bo</p>
<p class="p1">00000190:<span class="Apple-converted-space">  </span>64 79 3e 3c 2f 68 74 6d 6c 3e<span class="Apple-converted-space">  </span>dy&gt;&lt;/html&gt;</p>
</body>
</html>


Snippet demonstrating problem with SWT Clipboard.

	public void run(IAction action) {
		Clipboard clipboard = new Clipboard(Display.getCurrent());
		Object[] data = new Object[]{getHtmlContent(), getTextContent()};
		Transfer[] dataTypes = new Transfer[]{HTMLTransfer.getInstance(), TextTransfer.getInstance()};
		clipboard.setContents(data, dataTypes);
		clipboard.dispose();
		clipboard = null;
		MessageDialog.openInformation(null, "CopyToClipboardAction", "Copied data to clipboard.");
	}

	public void selectionChanged(IAction action, ISelection selection) {
	}

	private String getTextContent() {
		return "this is plain text content";
	}
	
	private String getHtmlContent() {
		String htmlContent = "<html><head></head><body><div id=\"ltsample\">This is some <i>html</i> text.  My phone number is <b>234-234-2342</b></div></body></html>";
		return htmlContent;
	}


Reproducible: Always
Comment 1 Fan Peng CLA 2011-03-30 03:57:06 EDT
I think this problem caused by HTMLTransfer in swt-carbon,swt-cocoa hasn't this problem.
In carbon HTMLTransfer.javaToNative,It use the following code to transfer the String object to an byte array.

	string.getChars(0, count, chars, 0);
	byte[] buffer = new byte[chars.length * 2];
	OS.memmove(buffer, chars, buffer.length);
	transferData.data = new byte[1][];
	transferData.data[0] = buffer;

I have debug these code,it will transfer the String to an byte array use charset "UTF-16LE" in MAC.
The "UTF-16LE" and "UTF-16BE" charset  hasn't the "Byte order mark" character at the beginning of the array.So the MAC can not decode these two charsets correctly,It cause this problem.

If we use String.getBytes("UTF-8") or  String.getBytes("UTF-16") instead the String-byte array transfer code in HTMLTransfer.javaToNative, It will works correctly.We can also add "Byte order mark" character at the beginning of the UTF-16LE/UTF-16BE  array to fixed this problem.

FYI:

Input html String:
<html><head></head><body><div
id=\"ltsample\">This is some <i>html</i> text.  My phone number is
<b>234-234-2342</b></div></body></html>


UTF-8 byte array of this String(can be decoded successfully):
[60, 104, 116, 109, 108, 62, 60, 104, 101, 97, 100, 62, 60, 47, 104, 101, 97, 100, 62, 60, 98, 111, 100, 121, 62, 60, 100, 105, 118, 32, 105, 100, 61, 34, 108, 116, 115, 97, 109, 112, 108, 101, 34, 62, 84, 104, 105, 115, 32, 105, 115, 32, 115, 111, 109, 101, 32, 60, 105, 62, 104, 116, 109, 108, 60, 47, 105, 62, 32, 116, 101, 120, 116, 46, 32, 32, 77, 121, 32, 112, 104, 111, 110, 101, 32, 110, 117, 109, 98, 101, 114, 32, 105, 115, 32, 60, 98, 62, 50, 51, 52, 45, 50, 51, 52, 45, 50, 51, 52, 50, 60, 47, 98, 62, 60, 47, 100, 105, 118, 62, 60, 47, 98, 111, 100, 121, 62, 60, 47, 104, 116, 109, 108, 62]


UTF-16 byte array of this String(can be decoded successfully, the first two elements is "Byte order mark"):
[-2, -1, 0, 60, 0, 104, 0, 116, 0, 109, 0, 108, 0, 62, 0, 60, 0, 104, 0, 101, 0, 97, 0, 100, 0, 62, 0, 60, 0, 47, 0, 104, 0, 101, 0, 97, 0, 100, 0, 62, 0, 60, 0, 98, 0, 111, 0, 100, 0, 121, 0, 62, 0, 60, 0, 100, 0, 105, 0, 118, 0, 32, 0, 105, 0, 100, 0, 61, 0, 34, 0, 108, 0, 116, 0, 115, 0, 97, 0, 109, 0, 112, 0, 108, 0, 101, 0, 34, 0, 62, 0, 84, 0, 104, 0, 105, 0, 115, 0, 32, 0, 105, 0, 115, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101, 0, 32, 0, 60, 0, 105, 0, 62, 0, 104, 0, 116, 0, 109, 0, 108, 0, 60, 0, 47, 0, 105, 0, 62, 0, 32, 0, 116, 0, 101, 0, 120, 0, 116, 0, 46, 0, 32, 0, 32, 0, 77, 0, 121, 0, 32, 0, 112, 0, 104, 0, 111, 0, 110, 0, 101, 0, 32, 0, 110, 0, 117, 0, 109, 0, 98, 0, 101, 0, 114, 0, 32, 0, 105, 0, 115, 0, 32, 0, 60, 0, 98, 0, 62, 0, 50, 0, 51, 0, 52, 0, 45, 0, 50, 0, 51, 0, 52, 0, 45, 0, 50, 0, 51, 0, 52, 0, 50, 0, 60, 0, 47, 0, 98, 0, 62, 0, 60, 0, 47, 0, 100, 0, 105, 0, 118, 0, 62, 0, 60, 0, 47, 0, 98, 0, 111, 0, 100, 0, 121, 0, 62, 0, 60, 0, 47, 0, 104, 0, 116, 0, 109, 0, 108, 0, 62]

UTF-16BE(can not be decoded successfully)
[0, 60, 0, 104, 0, 116, 0, 109, 0, 108, 0, 62, 0, 60, 0, 104, 0, 101, 0, 97, 0, 100, 0, 62, 0, 60, 0, 47, 0, 104, 0, 101, 0, 97, 0, 100, 0, 62, 0, 60, 0, 98, 0, 111, 0, 100, 0, 121, 0, 62, 0, 60, 0, 100, 0, 105, 0, 118, 0, 32, 0, 105, 0, 100, 0, 61, 0, 34, 0, 108, 0, 116, 0, 115, 0, 97, 0, 109, 0, 112, 0, 108, 0, 101, 0, 34, 0, 62, 0, 84, 0, 104, 0, 105, 0, 115, 0, 32, 0, 105, 0, 115, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101, 0, 32, 0, 60, 0, 105, 0, 62, 0, 104, 0, 116, 0, 109, 0, 108, 0, 60, 0, 47, 0, 105, 0, 62, 0, 32, 0, 116, 0, 101, 0, 120, 0, 116, 0, 46, 0, 32, 0, 32, 0, 77, 0, 121, 0, 32, 0, 112, 0, 104, 0, 111, 0, 110, 0, 101, 0, 32, 0, 110, 0, 117, 0, 109, 0, 98, 0, 101, 0, 114, 0, 32, 0, 105, 0, 115, 0, 32, 0, 60, 0, 98, 0, 62, 0, 50, 0, 51, 0, 52, 0, 45, 0, 50, 0, 51, 0, 52, 0, 45, 0, 50, 0, 51, 0, 52, 0, 50, 0, 60, 0, 47, 0, 98, 0, 62, 0, 60, 0, 47, 0, 100, 0, 105, 0, 118, 0, 62, 0, 60, 0, 47, 0, 98, 0, 111, 0, 100, 0, 121, 0, 62, 0, 60, 0, 47, 0, 104, 0, 116, 0, 109, 0, 108, 0, 62]


UTF-16LE(can not be decoded successfully)
[60, 0, 104, 0, 116, 0, 109, 0, 108, 0, 62, 0, 60, 0, 104, 0, 101, 0, 97, 0, 100, 0, 62, 0, 60, 0, 47, 0, 104, 0, 101, 0, 97, 0, 100, 0, 62, 0, 60, 0, 98, 0, 111, 0, 100, 0, 121, 0, 62, 0, 60, 0, 100, 0, 105, 0, 118, 0, 32, 0, 105, 0, 100, 0, 61, 0, 34, 0, 108, 0, 116, 0, 115, 0, 97, 0, 109, 0, 112, 0, 108, 0, 101, 0, 34, 0, 62, 0, 84, 0, 104, 0, 105, 0, 115, 0, 32, 0, 105, 0, 115, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101, 0, 32, 0, 60, 0, 105, 0, 62, 0, 104, 0, 116, 0, 109, 0, 108, 0, 60, 0, 47, 0, 105, 0, 62, 0, 32, 0, 116, 0, 101, 0, 120, 0, 116, 0, 46, 0, 32, 0, 32, 0, 77, 0, 121, 0, 32, 0, 112, 0, 104, 0, 111, 0, 110, 0, 101, 0, 32, 0, 110, 0, 117, 0, 109, 0, 98, 0, 101, 0, 114, 0, 32, 0, 105, 0, 115, 0, 32, 0, 60, 0, 98, 0, 62, 0, 50, 0, 51, 0, 52, 0, 45, 0, 50, 0, 51, 0, 52, 0, 45, 0, 50, 0, 51, 0, 52, 0, 50, 0, 60, 0, 47, 0, 98, 0, 62, 0, 60, 0, 47, 0, 100, 0, 105, 0, 118, 0, 62, 0, 60, 0, 47, 0, 98, 0, 111, 0, 100, 0, 121, 0, 62, 0, 60, 0, 47, 0, 104, 0, 116, 0, 109, 0, 108, 0, 62, 0]


UTF-16LE(can be decoded successfully, added "Byte order mark" manually)
[-1, -2, 60, 0, 104, 0, 116, 0, 109, 0, 108, 0, 62, 0, 60, 0, 104, 0, 101, 0, 97, 0, 100, 0, 62, 0, 60, 0, 47, 0, 104, 0, 101, 0, 97, 0, 100, 0, 62, 0, 60, 0, 98, 0, 111, 0, 100, 0, 121, 0, 62, 0, 60, 0, 100, 0, 105, 0, 118, 0, 32, 0, 105, 0, 100, 0, 61, 0, 34, 0, 108, 0, 116, 0, 115, 0, 97, 0, 109, 0, 112, 0, 108, 0, 101, 0, 34, 0, 62, 0, 84, 0, 104, 0, 105, 0, 115, 0, 32, 0, 105, 0, 115, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101, 0, 32, 0, 60, 0, 105, 0, 62, 0, 104, 0, 116, 0, 109, 0, 108, 0, 60, 0, 47, 0, 105, 0, 62, 0, 32, 0, 116, 0, 101, 0, 120, 0, 116, 0, 46, 0, 32, 0, 32, 0, 77, 0, 121, 0, 32, 0, 112, 0, 104, 0, 111, 0, 110, 0, 101, 0, 32, 0, 110, 0, 117, 0, 109, 0, 98, 0, 101, 0, 114, 0, 32, 0, 105, 0, 115, 0, 32, 0, 60, 0, 98, 0, 62, 0, 50, 0, 51, 0, 52, 0, 45, 0, 50, 0, 51, 0, 52, 0, 45, 0, 50, 0, 51, 0, 52, 0, 50, 0, 60, 0, 47, 0, 98, 0, 62, 0, 60, 0, 47, 0, 100, 0, 105, 0, 118, 0, 62, 0, 60, 0, 47, 0, 98, 0, 111, 0, 100, 0, 121, 0, 62, 0, 60, 0, 47, 0, 104, 0, 116, 0, 109, 0, 108, 0, 62, 0]
Comment 2 Silenio Quarti CLA 2011-03-30 18:13:13 EDT
This is fix in 3.6.2 and e.7 already.

*** This bug has been marked as a duplicate of bug 330122 ***
Comment 3 Silenio Quarti CLA 2011-03-30 18:13:59 EDT
meant to say 3.6.2 and 3.7...