diff --git a/pywps/inout/inputs.py b/pywps/inout/inputs.py index c7202d53e..0fa3a5c08 100644 --- a/pywps/inout/inputs.py +++ b/pywps/inout/inputs.py @@ -3,6 +3,7 @@ # licensed under MIT, Please consult LICENSE.txt for details # ################################################################## +import re import lxml.etree as etree import six @@ -14,6 +15,8 @@ from pywps.validator.mode import MODE from pywps.inout.literaltypes import AnyValue, NoValue, ValuesReference, AllowedValue +CDATA_PATTERN = re.compile(r'') + class BoundingBoxInput(basic.BBoxInput): @@ -214,7 +217,12 @@ def from_json(cls, json_input): elif json_input.get('href'): instance.url = json_input['href'] elif json_input.get('data'): - instance.data = json_input['data'] + data = json_input['data'] + # remove cdata tag if it exists (issue #553) + match = CDATA_PATTERN.match(data) + if match: + data = match.group(1) + instance.data = data return instance diff --git a/tests/test_inout.py b/tests/test_inout.py index 8953ad2c4..ab436d711 100644 --- a/tests/test_inout.py +++ b/tests/test_inout.py @@ -288,9 +288,10 @@ def test_complex_input_file(self): def test_complex_input_data(self): complex = self.make_complex_input() complex.data = "some data" + # the data is enclosed by a CDATA tag in json + assert complex.json['data'] == '' + # dump to json and load it again complex2 = inout.inputs.ComplexInput.from_json(complex.json) - # the data is enclosed by a CDATA tag - complex._data = u''.format(complex.data) # it's expected that the file path changed complex._file = complex2.file @@ -299,14 +300,14 @@ def test_complex_input_data(self): def test_complex_input_stream(self): complex = self.make_complex_input() - complex.stream = StringIO("some data") + complex.stream = StringIO("{'name': 'test', 'input1': ']]'}") + # the data is enclosed by a CDATA tag in json + assert complex.json['data'] == "" + # dump to json and load it again complex2 = inout.inputs.ComplexInput.from_json(complex.json) - # the serialized stream becomes a data type # we hard-code it for the testing comparison complex.prop = 'data' - # the data is enclosed by a CDATA tag - complex._data = u''.format(complex.data) # it's expected that the file path changed complex._file = complex2.file @@ -682,8 +683,8 @@ class LiteralOutputTest(unittest.TestCase): def setUp(self): self.literal_output = inout.outputs.LiteralOutput( - "literaloutput", - data_type="integer", + "literaloutput", + data_type="integer", title="Literal Output", translations={"fr-CA": {"title": "Mon output", "abstract": "Une description"}}, ) @@ -714,8 +715,8 @@ class BBoxInputTest(unittest.TestCase): def setUp(self): self.bbox_input = inout.inputs.BoundingBoxInput( - "bboxinput", - title="BBox input", + "bboxinput", + title="BBox input", dimensions=2, translations={"fr-CA": {"title": "Mon input", "abstract": "Une description"}}, )