wcs: send quoted tracking code to wcs (#32646)

This commit is contained in:
Thomas NOËL 2019-04-26 12:39:49 +02:00
parent a38bcdc803
commit ed5b366a6b
2 changed files with 9 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import re
from django.contrib import messages from django.contrib import messages
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import JsonResponse, HttpResponseRedirect, HttpResponseBadRequest from django.http import JsonResponse, HttpResponseRedirect, HttpResponseBadRequest
from django.utils.http import urlquote
from django.utils.six.moves.urllib import parse as urlparse from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
@ -47,7 +48,7 @@ class TrackingCodeView(View):
wcs_sites = get_wcs_services().values() wcs_sites = get_wcs_services().values()
for wcs_site in wcs_sites: for wcs_site in wcs_sites:
response = requests.get('/api/code/' + code, response = requests.get('/api/code/' + urlquote(code),
remote_service=wcs_site, log_errors=False) remote_service=wcs_site, log_errors=False)
if response.status_code == 200 and response.json().get('err') == 0: if response.status_code == 200 and response.json().get('err') == 0:
return response.json().get('load_url') return response.json().get('load_url')

View File

@ -622,6 +622,13 @@ def test_tracking_code_cell(app):
resp = resp.follow() resp = resp.follow()
assert '<li class="error">The tracking code could not been found.</li>' in resp.text assert '<li class="error">The tracking code could not been found.</li>' in resp.text
resp = app.get('/')
resp.form['code'] = 'FOO?BAR?bad<code>'
resp = resp.form.submit()
assert resp.status_code == 302
resp = resp.follow()
assert '<li class="error">The tracking code could not been found.</li>' in resp.text
resp = app.get('/') resp = app.get('/')
resp.form['code'] = 'CNPHNTFB' resp.form['code'] = 'CNPHNTFB'
resp = resp.form.submit() resp = resp.form.submit()