csvdatasource: force string cast before eval (#43117)

This commit is contained in:
Thomas NOËL 2020-06-03 12:05:13 +02:00
parent cfab042108
commit 59cdda0b72
2 changed files with 8 additions and 2 deletions

View File

@ -27,7 +27,7 @@ from pyexcel_ods import get_data as get_data_ods
from pyexcel_xls import get_data as get_data_xls
from django.contrib.postgres.fields import JSONField
from django.utils.encoding import force_str, smart_text
from django.utils.encoding import force_str, smart_text, force_text
from django.utils.timezone import datetime, make_aware
from django.conf import settings
from django.db import models, transaction
@ -414,7 +414,7 @@ class CsvDataSource(BaseResource):
if 'id' in request.GET:
# always provide a ?id= filter.
filters = ["id == %r" % request.GET['id']]
filters = ["id == %r" % force_text(request.GET['id'])]
data = [row for new_row, row in stream_expressions(filters, data, kind='filters')
if new_row[0]]

View File

@ -410,6 +410,12 @@ def test_query_q_filter(app, setup, filetype):
response = app.get(url + '?q=sandra')
assert response.json['err'] == 0
assert len(response.json['data']) == 2
response = app.get(url + '?' + urlencode({'q': 'Benoît'}))
assert response.json['err'] == 0
assert len(response.json['data']) == 1
response = app.get(url + '?q=benoit')
assert response.json['err'] == 0
assert len(response.json['data']) == 1
def test_query_dict(app, setup, filetype):