Fix & test query string parsing
This commit is contained in:
parent
75ccb97069
commit
5a92505606
2 changed files with 9 additions and 5 deletions
|
@ -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):
|
||||
|
|
|
@ -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/'
|
||||
|
|
Loading…
Reference in a new issue