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:
parent
cb3d1196f2
commit
e92b1969e8
@ -222,6 +222,8 @@ class RemoteIndexSource(BaseIndexSource):
|
|||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
class XmlQueryIndexSource(BaseIndexSource):
|
class XmlQueryIndexSource(BaseIndexSource):
|
||||||
|
EXACT_QUERY = 'type:urlquery url:'
|
||||||
|
PREFIX_QUERY = 'type:prefixquery url:'
|
||||||
|
|
||||||
def __init__(self, query_api_url):
|
def __init__(self, query_api_url):
|
||||||
self.query_api_url = query_api_url
|
self.query_api_url = query_api_url
|
||||||
@ -235,13 +237,16 @@ class XmlQueryIndexSource(BaseIndexSource):
|
|||||||
matchType = params.get('matchType', 'exact')
|
matchType = params.get('matchType', 'exact')
|
||||||
|
|
||||||
if 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':
|
elif matchType == 'prefix':
|
||||||
query_url = self.query_api_url + '?q=' + quote_plus('type:prefixquery url:' + quote_plus(url))
|
query = self.PREFIX_QUERY
|
||||||
else:
|
else:
|
||||||
raise BadRequestException('matchType={0} is not supported'.format(matchType=matchType))
|
raise BadRequestException('matchType={0} is not supported'.format(matchType=matchType))
|
||||||
|
|
||||||
try:
|
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)
|
self.logger.debug("Running query: %s" % query_url)
|
||||||
response = self.session.get(query_url)
|
response = self.session.get(query_url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
@ -10,14 +10,14 @@ import pytest
|
|||||||
# ============================================================================
|
# ============================================================================
|
||||||
def mock_get(self, url):
|
def mock_get(self, url):
|
||||||
string = ''
|
string = ''
|
||||||
if 'type:urlquery' in url:
|
if 'type%3Aurlquery' in url:
|
||||||
if 'http%3A%2F%2Fexample.com%2Fsome%2Fpath' in url:
|
if 'http%253A%252F%252Fexample.com%252Fsome%252Fpath' in url:
|
||||||
string = URL_RESPONSE_2
|
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
|
string = URL_RESPONSE_1
|
||||||
|
|
||||||
elif 'type:prefixquery' in url:
|
elif 'type%3Aprefixquery' in url:
|
||||||
string = PREFIX_QUERY
|
string = PREFIX_QUERY
|
||||||
|
|
||||||
class MockResponse(object):
|
class MockResponse(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user