diff --git a/src/gpodder/gtkui/interface/addpodcast.py b/src/gpodder/gtkui/interface/addpodcast.py index a094a80a9..97bef3f98 100644 --- a/src/gpodder/gtkui/interface/addpodcast.py +++ b/src/gpodder/gtkui/interface/addpodcast.py @@ -49,9 +49,10 @@ def new(self): 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 @@ def on_btn_paste_clicked(self, widget): 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')) diff --git a/src/gpodder/util.py b/src/gpodder/util.py index 9523e45d8..edc48b757 100644 --- a/src/gpodder/util.py +++ b/src/gpodder/util.py @@ -73,14 +73,14 @@ 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.