Bug 423201 - Code from Firefox pastes extra newlines into Konsole
Summary: Code from Firefox pastes extra newlines into Konsole
Status: RESOLVED DUPLICATE of bug 421480
Alias: None
Product: konsole
Classification: Applications
Component: copy-paste (show other bugs)
Version: unspecified
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-19 01:29 UTC by Ulrich Norbisrath
Modified: 2020-06-23 16:22 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Norbisrath 2020-06-19 01:29:29 UTC
SUMMARY
Code or commands cannot be pasted from firefox into konsole as firefox puts linefeed (/n - 10) carriage return (/r - 13) into the clipboard.

STEPS TO REPRODUCE
1. Open https://www.reddit.com/r/kde/comments/gv89gw/double_newlines_when_pasting_into_konsole_and/ in Firefox.
2. Select the echo echo echo block. Press Ctrl-C.

OBSERVED RESULT
3. Paste either per middle mouse-click or per Ctrl-V into konsole, see double new-lines.
4. Check also xclip -o | hexdump and witness several 0a0d


EXPECTED RESULT
No double new-lines. Carriage-Return is simply ignored like in xterm, gnome-terminal, xfce4-terminal, or qterminal

SOFTWARE/OS VERSIONS
Windows: n/a
macOS: n/a
Linux/KDE Plasma: Manjaro (updated) 
(available in About System)
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.70.0
Qt Version: 5.15.0

ADDITIONAL INFORMATION
klipper is installed and active (but I recall having same issues without clipboard manager or with copyq - there are some rare instances where it works sometimes correctly, but not sure how to reproduce). Inserting from selection or clipboard via middle-click into konsole has same result. Setting synchronize content in klipper doesn't change anything.

Another report like this: https://www.reddit.com/r/kde/comments/cm0j3d/konsole_add_newline_when_copying/
Comment 1 Ahmad Samir 2020-06-19 01:34:57 UTC

*** This bug has been marked as a duplicate of bug 421480 ***
Comment 2 Ahmad Samir 2020-06-19 12:09:35 UTC
Reopened as per bug 421480 comment5.
Comment 3 Ulrich Norbisrath 2020-06-19 12:35:33 UTC
Just adding here a more precise prescription to see the problem of lf/cr ending up in the clipboard (hope somebody else can confirm):
1. use klipper (enable the kde clipboard)
2. in klipper make sure you enable "synchronize contents of the clipboard and the selection" in it's configuration
3. open in firefox "https://www.reddit.com/r/kde/comments/gv89gw/double_newlines_when_pasting_into_konsole_and/" and navigate to the code box that shows 3x echo
4. select the three echos
5. press ctrl-c (don't skip this step if you paste directly from selection it will work after the fix mentioned in bug 421480
6. check in a terminal: xclip -o|hexdump
7. hopefully confirm that you also see 0a0d sequences in that output (else something else weird is going on in my system)
8. press either shft-ctrl-v or middle-mouse-klick in a konsole with command-prompt
9. witness extra new-lines (one from echo showing without prompt, and one for the prompt)
10. maybe also try with vim and report back (I don't have the fix installed yet)
Comment 4 Ahmad Samir 2020-06-20 13:52:18 UTC
With the fix from bug 421480, I can't reproduce the issue you describe.

(echo is a command, if you type echo then press enter, it'll output an empty line).
Comment 5 Ulrich Norbisrath 2020-06-20 14:42:49 UTC
(In reply to Ahmad Samir from comment #4)
> With the fix from bug 421480, I can't reproduce the issue you describe.
> 
> (echo is a command, if you type echo then press enter, it'll output an empty
> line).

I know that echo produces a new line, but I get in addition an empty command prompt each time. Just as if I had pressed enter without doing a command.

But if it doesn't happen on your end, it might just be something weird with firefox, reddit, klipper, and manjaro. I will wait a couple of months for the patch to come through and then report back - I switched to xfce4-terminal for the time being.
Comment 6 Ahmad Samir 2020-06-20 14:54:05 UTC
I see. Reverting the fix from bug 421480, I get:
ahmad:~/.../building-dir/src>$ echo

ahmad:~/.../building-dir/src>$ 
ahmad:~/.../building-dir/src>$ echo

ahmad:~/.../building-dir/src>$ 
ahmad:~/.../building-dir/src>$ echo

however with the fix:
ahmad:~/.../building-dir/src>$ echo

ahmad:~/.../building-dir/src>$ echo

ahmad:~/.../building-dir/src>$ echo

if this matches what you're seeing, then this is a duplicate of the other bug. :)

FWIW, distro package maintainers sometimes backport fixes from upstream (especially if the fix doesn't include too many code changes, and this one is a one-liner), so it might be worthwhile to file a bug report in your distro bug tracker.
Comment 7 Ulrich Norbisrath 2020-06-20 17:52:39 UTC
That's exactly what I get, yes.
However, I was worried about the hexdump showing the crlf in reverse order (maybe that's somewhow an endian-problem), but maybe it somehow is solved.

Maybe, I can manage to get this here updated and compile it myself - as I understood your patch is already upstream, isn't it?

https://aur.archlinux.org/packages/konsole-git
Comment 8 Ahmad Samir 2020-06-20 18:12:24 UTC
A link to the commit is posted by the git hooks that close the bug report https://invent.kde.org/utilities/konsole/commit/a1022442dc2f59321976fd3456ad97c61300d1f2

*** This bug has been marked as a duplicate of bug 421480 ***
Comment 9 Ulrich Norbisrath 2020-06-23 13:19:02 UTC
(In reply to Ulrich Norbisrath from comment #7)
> Maybe, I can manage to get this here updated and compile it myself - as I
> understood your patch is already upstream, isn't it?
> 
> https://aur.archlinux.org/packages/konsole-git

I thought I commented that after compiling my own version the bug was gone for me too, but somehow it didn't register.

So, yes using the adapted aur for compiling latest version from git of konsole fixes the problem.
Comment 10 Ulrich Norbisrath 2020-06-23 16:22:16 UTC
However, any of these fixes don't solve the root cause that it's often nearly impossible to copy code examples from Firefox in kde - if you try to copy code from realpython it will always result in double newlines (also when pasting to other shells or into kate): https://realpython.com/pysimplegui-python/#integrating-opencv-with-pysimplegui

Copying source-code from realpython from example will always create double newlines. Shall I open ticket for Firefox?

Copying from chromium or konqueror works.