Added logic to trim away leading/trailing whitespaces in user-clipboard auto-inputted urls (#1276)
* Added logic to trim away leading/trailing whitespaces in user-inputted urls. Tested against current gpodder-installe executable for correct/ desired behaviour. simplified receive_clipboard_text method of class gPodderAddPodcast in addpodcast.py resolves #520
This commit is contained in:
parent
d7ad5f3f13
commit
778f5b708c
|
@ -49,9 +49,10 @@ class gPodderAddPodcast(BuilderWidget):
|
|||
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
||||
|
||||
def receive_clipboard_text(clipboard, text, second_try):
|
||||
# Heuristic: If there is a space in the clipboard
|
||||
# text, assume it's some arbitrary text, and no URL
|
||||
if text is not None and ' ' not in text:
|
||||
# Heuristic: If space is present in clipboard text
|
||||
# normalize_feed_url will either fix to valid url or
|
||||
# return None if URL cannot be validated
|
||||
if text is not None:
|
||||
url = util.normalize_feed_url(text)
|
||||
if url is not None:
|
||||
self.entry_url.set_text(url)
|
||||
|
@ -72,7 +73,7 @@ class gPodderAddPodcast(BuilderWidget):
|
|||
|
||||
def receive_clipboard_text(self, clipboard, text, data=None):
|
||||
if text is not None:
|
||||
self.entry_url.set_text(text)
|
||||
self.entry_url.set_text(text).strip()
|
||||
else:
|
||||
self.show_message(_('Nothing to paste.'), _('Clipboard is empty'))
|
||||
|
||||
|
|
|
@ -73,14 +73,14 @@ logger = logging.getLogger(__name__)
|
|||
try:
|
||||
import html5lib
|
||||
except ImportError:
|
||||
logger.warn('html5lib not found, falling back to HTMLParser')
|
||||
logger.warning("html5lib was not found, fall-back to HTMLParser")
|
||||
html5lib = None
|
||||
|
||||
if gpodder.ui.win32:
|
||||
try:
|
||||
import gpodder.utilwin32ctypes as win32file
|
||||
except ImportError:
|
||||
logger.warn('Running on Win32 but utilwin32ctypes can\'t be loaded.')
|
||||
logger.warning('Running on Win32: utilwin32ctypes cannot be loaded')
|
||||
win32file = None
|
||||
|
||||
_ = gpodder.gettext
|
||||
|
@ -248,6 +248,12 @@ def normalize_feed_url(url):
|
|||
if not url or len(url) < 8:
|
||||
return None
|
||||
|
||||
# Removes leading and/or trailing whitespaces - if url contains whitespaces
|
||||
# in between after str.strip() -> conclude invalid url & return None
|
||||
url = url.strip()
|
||||
if ' ' in url:
|
||||
return None
|
||||
|
||||
# This is a list of prefixes that you can use to minimize the amount of
|
||||
# keystrokes that you have to use.
|
||||
# Feel free to suggest other useful prefixes, and I'll add them here.
|
||||
|
|
Loading…
Reference in New Issue