1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

xmlindexsource: fix tests for double escaping of query (for ukwa/ukwa-pywb#29)

This commit is contained in:
Ilya Kreymer 2019-03-07 14:11:47 -08:00 committed by John Berlin
parent cb3d1196f2
commit e92b1969e8
No known key found for this signature in database
GPG Key ID: 6EF5E4B442011B02
2 changed files with 11 additions and 6 deletions

View File

@ -222,6 +222,8 @@ class RemoteIndexSource(BaseIndexSource):
# =============================================================================
class XmlQueryIndexSource(BaseIndexSource):
EXACT_QUERY = 'type:urlquery url:'
PREFIX_QUERY = 'type:prefixquery url:'
def __init__(self, query_api_url):
self.query_api_url = query_api_url
@ -235,13 +237,16 @@ class XmlQueryIndexSource(BaseIndexSource):
matchType = params.get('matchType', 'exact')
if matchType == 'exact':
query_url = self.query_api_url + '?q=' + quote_plus('type:urlquery url:' + quote_plus(url))
query = self.EXACT_QUERY
elif matchType == 'prefix':
query_url = self.query_api_url + '?q=' + quote_plus('type:prefixquery url:' + quote_plus(url))
query = self.PREFIX_QUERY
else:
raise BadRequestException('matchType={0} is not supported'.format(matchType=matchType))
try:
#OpenSearch API requires double-escaping
#TODO: add option to not double escape if needed
query_url = self.query_api_url + '?q' + quote_plus(query + quote_plus(url))
self.logger.debug("Running query: %s" % query_url)
response = self.session.get(query_url)
response.raise_for_status()

View File

@ -10,14 +10,14 @@ import pytest
# ============================================================================
def mock_get(self, url):
string = ''
if 'type:urlquery' in url:
if 'http%3A%2F%2Fexample.com%2Fsome%2Fpath' in url:
if 'type%3Aurlquery' in url:
if 'http%253A%252F%252Fexample.com%252Fsome%252Fpath' in url:
string = URL_RESPONSE_2
elif 'http%3A%2F%2Fexample.com%2F' in url:
elif 'http%253A%252F%252Fexample.com%252F' in url:
string = URL_RESPONSE_1
elif 'type:prefixquery' in url:
elif 'type%3Aprefixquery' in url:
string = PREFIX_QUERY
class MockResponse(object):