Bug 528691 - [GTK] StyledText ignores text after \u0000 character
Summary: [GTK] StyledText ignores text after \u0000 character
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted, triaged
: 412659 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-12-13 04:28 EST by Thomas Singer CLA
Modified: 2020-11-18 21:39 EST (History)
6 users (show)

See Also:


Attachments
Sample code (666 bytes, text/plain)
2017-12-13 04:28 EST, Thomas Singer CLA
no flags Details
Screenshot on Windows 10 (7.83 KB, image/png)
2017-12-13 04:28 EST, Thomas Singer CLA
no flags Details
Screenshot on Ubuntu 16.04 (4.33 KB, image/png)
2017-12-13 04:29 EST, Thomas Singer CLA
no flags Details
debug variables screenshot (20.53 KB, image/png)
2020-02-06 20:27 EST, Jonah Graham CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Singer CLA 2017-12-13 04:28:05 EST
Please launch the attached sample on Windows and Linux. On Windows you can see the "world", on Linux you can't.
Comment 1 Thomas Singer CLA 2017-12-13 04:28:27 EST
Created attachment 271881 [details]
Sample code
Comment 2 Thomas Singer CLA 2017-12-13 04:28:46 EST
Created attachment 271882 [details]
Screenshot on Windows 10
Comment 3 Thomas Singer CLA 2017-12-13 04:29:07 EST
Created attachment 271883 [details]
Screenshot on Ubuntu 16.04
Comment 4 Eric Williams CLA 2017-12-13 10:34:55 EST
I can reproduce the issue on 4.8M4, GTK3.22, Fedora 27. Happens on GTK2.24 as well.
Comment 5 Björn Arnelid CLA 2017-12-14 11:00:02 EST
The eclipse console view will handle \u0000 in the same way, 
so doing a System.out.println will only show hello in eclipse console but helloworld in a consol (at least my console in Linux mint).

Also variables view and tooltip when debugging will display hello rather then helloworld.
Comment 6 Eclipse Genie CLA 2017-12-18 04:17:41 EST
New Gerrit change created: https://git.eclipse.org/r/113593
Comment 7 Björn Arnelid CLA 2017-12-18 04:22:16 EST
I have submitted a fix that works for StyledText, the consol and for the variable view details pane. 

But it will still cut the string on the variable tree itself since TreeItems are specifically set to be null terminated.
Comment 8 Eric Williams CLA 2017-12-18 10:04:19 EST
(In reply to Björn Arnelid from comment #7)
> I have submitted a fix that works for StyledText, the consol and for the
> variable view details pane. 
> 
> But it will still cut the string on the variable tree itself since TreeItems
> are specifically set to be null terminated.

I'll take a look at your patch today.
Comment 9 Eclipse Genie CLA 2017-12-19 09:43:04 EST
New Gerrit change created: https://git.eclipse.org/r/114402
Comment 11 Eric Williams CLA 2017-12-19 09:46:50 EST
(In reply to Eclipse Genie from comment #10)
> Gerrit change https://git.eclipse.org/r/114402 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=aa9e2b45dfa29b90beca2ed2b31a641b04d8e925

Bug snippet merged.
Comment 12 Eric Williams CLA 2018-01-02 10:59:31 EST
When reviewing the patch for this bug, Bjorn and I ran into some issues which merit some discussion.

Displaying the text after the null terminator doesn't require much work. However we also need to fix copying + pasting, as displaying the text and then copying it only copies what comes before the null character. This means that the user would see "helloworld", but copying that text only copies "hello".

AFAIK, GTK clipboards are null terminated by default, so to fix this we'd have to strip out the null characters before sending them to the keyboard. I don't think this is a good approach though. It could lead to cases like malicious text being inserted after the null character which then end up in the clipboard. And after thinking about it, I'm not sure it's even reasonable to expect text after a null terminator to be displayed.

What do you think? Thomas, when running the snippet on Windows, what text is copied to the clipboard?
Comment 13 Thomas Singer CLA 2018-01-03 01:57:55 EST
On Windows 10 just "hello" is pasted if "hello\u0000world" had been copied.
Comment 14 Eric Williams CLA 2018-01-03 10:56:41 EST
(In reply to Thomas Singer from comment #13)
> On Windows 10 just "hello" is pasted if "hello\u0000world" had been copied.

I'm not sure if we should enable this behaviour on GTK, or if we should patch Windows to not display text after the null character. Or do nothing and add some info to the StyledText.setText() Javadocs about null characters.

IMO the user should expect that copying the text displayed in the StyledText would mean that all the text is copied, not some portion of it. I would prefer to leave GTK as it is and modify the Javadocs to reflect platform dependent behaviour when it comes to null terminated strings.

Does anyone else have any thoughts?
Comment 15 Björn Arnelid CLA 2018-01-03 11:42:47 EST
(In reply to Eric Williams from comment #14) 
> I'm not sure if we should enable this behaviour on GTK, or if we should
> patch Windows to not display text after the null character. Or do nothing
> and add some info to the StyledText.setText() Javadocs about null characters.
> 
> IMO the user should expect that copying the text displayed in the StyledText
> would mean that all the text is copied, not some portion of it. I would
> prefer to leave GTK as it is and modify the Javadocs to reflect platform
> dependent behaviour when it comes to null terminated strings.
> 
> Does anyone else have any thoughts?

I dont think i agree, StyledText is specifically trying to not be null terminated while displaying text and null terminated when copying text. It doesnt really makes sense that we are not honoring this in our converter?

If this is the behavior we want, should we not implement this fix and set StyledText to be null terminated, or make all strings null terminated in the linux Converter function to make it more clear that this is what is happening?
Comment 16 Eric Williams CLA 2018-01-03 11:53:30 EST
(In reply to Björn Arnelid from comment #15)
> 
> I dont think i agree, StyledText is specifically trying to not be null
> terminated while displaying text and null terminated when copying text. 

Is this the intention of StyledText? AFAICT the difference seems to be platform dependent, I don't see this in the documentation.
Comment 17 Björn Arnelid CLA 2018-01-03 17:50:29 EST
(In reply to Eric Williams from comment #16)
> Is this the intention of StyledText? AFAICT the difference seems to be
> platform dependent, I don't see this in the documentation.

It is not documented as far as i can see, but since the call to Converter is hard coded to false it seems to be intentional. There are a lot of other widgets using Converter that are supposed to be null terminated where this works as intended, Labels and TreeItems for instance.
Comment 18 Björn Arnelid CLA 2018-01-10 07:39:06 EST
Reading the method description again i(In reply to Eric Williams from comment #14)
> (In reply to Thomas Singer from comment #13)
> > On Windows 10 just "hello" is pasted if "hello\u0000world" had been copied.
> 
> I'm not sure if we should enable this behaviour on GTK, or if we should
> patch Windows to not display text after the null character. Or do nothing
> and add some info to the StyledText.setText() Javadocs about null characters.
> 
> IMO the user should expect that copying the text displayed in the StyledText
> would mean that all the text is copied, not some portion of it. I would
> prefer to leave GTK as it is and modify the Javadocs to reflect platform
> dependent behaviour when it comes to null terminated strings.
> 
> Does anyone else have any thoughts?

Actually after reading the method description again and digging around some more i do agree with you.
Comment 19 Thomas Singer CLA 2018-01-10 12:02:13 EST
Alternative suggestion: add a static String field with a setter. If it is empty, the \u0000 will not be escaped, otherwise the specified string will be escaped. That way any application developer can decide on its own how to handle this case.
Comment 20 Eric Williams CLA 2018-05-14 14:43:07 EDT
*** Bug 412659 has been marked as a duplicate of this bug. ***
Comment 21 Eric Williams CLA 2019-01-18 11:48:55 EST
(In reply to Thomas Singer from comment #19)
> Alternative suggestion: add a static String field with a setter. If it is
> empty, the \u0000 will not be escaped, otherwise the specified string will
> be escaped. That way any application developer can decide on its own how to
> handle this case.

Thomas if you are willing to provide a patch I will be happy to review it.
Comment 22 Jonah Graham CLA 2020-02-06 20:27:42 EST
Created attachment 281725 [details]
debug variables screenshot

Is this the same root cause for the Variables view not displaying characters after \0 containing strings? 

From the original example from Thomas, step into setText and you can see the variables view as attached shows the same error.
Comment 23 Björn Arnelid CLA 2020-02-07 03:05:11 EST
(In reply to Jonah Graham from comment #22)
> Created attachment 281725 [details]
> debug variables screenshot
> 
> Is this the same root cause for the Variables view not displaying characters
> after \0 containing strings? 
> 
> From the original example from Thomas, step into setText and you can see the
> variables view as attached shows the same error.

Yes, see Comment #5.
Comment 24 Kit Lo CLA 2020-11-18 21:39:58 EST
Any updates for this issue? How about a preference for displaying text after the null terminator and let the user pick?