Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cdata deserialzation #555

Merged
merged 2 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pywps/inout/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# licensed under MIT, Please consult LICENSE.txt for details #
##################################################################

import re
import lxml.etree as etree
import six

Expand All @@ -14,6 +15,8 @@
from pywps.validator.mode import MODE
from pywps.inout.literaltypes import AnyValue, NoValue, ValuesReference, AllowedValue

CDATA_PATTERN = re.compile(r'<!\[CDATA\[(.*?)\]\]>')


class BoundingBoxInput(basic.BBoxInput):

Expand Down Expand Up @@ -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

Expand Down
21 changes: 11 additions & 10 deletions tests/test_inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] == '<![CDATA[some 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'<![CDATA[{}]]>'.format(complex.data)
# it's expected that the file path changed
complex._file = complex2.file

Expand All @@ -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'] == "<![CDATA[{'name': 'test', 'input1': ']]'}]]>"
# 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'<![CDATA[{}]]>'.format(complex.data)
# it's expected that the file path changed
complex._file = complex2.file

Expand Down Expand Up @@ -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"}},
)
Expand Down Expand Up @@ -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"}},
)
Expand Down