diff --git a/dosagelib/util.py b/dosagelib/util.py index 2ac5c7dad..59ea2998e 100644 --- a/dosagelib/util.py +++ b/dosagelib/util.py @@ -5,13 +5,12 @@ from __future__ import absolute_import, division, print_function -from six.moves.urllib.parse import ( +from six.moves.urllib.parse import (parse_qs, quote as url_quote, unquote as url_unquote, urlparse, urlunparse, urlsplit) from six.moves.urllib_robotparser import RobotFileParser import requests import sys import os -import cgi import re import traceback import time @@ -321,9 +320,9 @@ def getRelativePath(basepath, path): def getQueryParams(url): """Get URL query parameters.""" - query = urlsplit(url)[3] + query = urlsplit(url).query out.debug(u'Extracting query parameters from %r (%r)...' % (url, query)) - return cgi.parse_qs(query) + return parse_qs(query) def internal_error(out=sys.stderr, etype=None, evalue=None, tb=None): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index b02af22fe..196032e17 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -3,7 +3,7 @@ from __future__ import absolute_import, division, print_function -from dosagelib.helpers import joinPathPartsNamer +from dosagelib.helpers import joinPathPartsNamer, queryNamer class TestNamer(object): @@ -11,6 +11,11 @@ class TestNamer(object): Tests for comic namer. """ + def test_queryNamer(self): + testurl = 'http://FOO?page=result&page2=result2' + assert queryNamer('page')(self, testurl, "") == 'result' + assert queryNamer('page2', True)(self, "", testurl) == 'result2' + def test_joinPathPartsNamer(self): imgurl = 'https://HOST/wp-content/uploads/2019/02/tennis5wp-1.png' pageurl = 'https://HOST/2019/03/11/12450/'