From 14042403f689931b5a88a171183c1549e0c8374e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 2 Feb 2016 06:37:49 +0100 Subject: [PATCH] Fix pasting of empty URLs. --- qutebrowser/browser/commands.py | 4 ++-- tests/integration/features/conftest.py | 1 + tests/integration/features/yankpaste.feature | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index da01cd06f..503634c7e 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -826,11 +826,11 @@ class CommandDispatcher: mode = QClipboard.Clipboard target = "Clipboard" text = clipboard.text(mode) - if not text: + if not text.strip(): raise cmdexc.CommandError("{} is empty.".format(target)) log.misc.debug("{} contained: '{}'".format(target, text.replace('\n', '\\n'))) - text_urls = enumerate(u for u in text.split('\n') if u) + text_urls = enumerate(u for u in text.split('\n') if u.strip()) for i, text_url in text_urls: if not window and i > 0: tab = False diff --git a/tests/integration/features/conftest.py b/tests/integration/features/conftest.py index 1208cf42e..1fe694246 100644 --- a/tests/integration/features/conftest.py +++ b/tests/integration/features/conftest.py @@ -210,6 +210,7 @@ def selection_supported(qapp): def fill_clipboard(qtbot, qapp, httpbin, what, content): mode = _clipboard_mode(qapp, what) content = content.replace('(port)', str(httpbin.port)) + content = content.replace(r'\n', '\n') clipboard = qapp.clipboard() with qtbot.waitSignal(clipboard.changed): diff --git a/tests/integration/features/yankpaste.feature b/tests/integration/features/yankpaste.feature index 40255b6e5..b1e329ce9 100644 --- a/tests/integration/features/yankpaste.feature +++ b/tests/integration/features/yankpaste.feature @@ -61,6 +61,11 @@ Feature: Yanking and pasting. And I run :paste --sel Then the error "Primary selection is empty." should be shown + Scenario: Pasting with a space in clipboard + When I put " " into the clipboard + And I run :paste + Then the error "Clipboard is empty." should be shown + Scenario: Pasting in a new tab Given I open about:blank When I run :tab-only @@ -171,6 +176,18 @@ Feature: Yanking and pasting. - active: true url: http://localhost:*/data/hello3.txt + Scenario: Pasting multiple urls with an empty one + When I open about:blank + And I put "http://localhost:(port)/data/hello.txt\n\nhttp://localhost:(port)/data/hello2.txt" into the clipboard + And I run :paste -t + Then no crash should happen + + Scenario: Pasting multiple urls with an almost empty one + When I open about:blank + And I put "http://localhost:(port)/data/hello.txt\n \nhttp://localhost:(port)/data/hello2.txt" into the clipboard + And I run :paste -t + Then no crash should happen + #### :paste-primary Scenario: Pasting the primary selection into an empty text field