Commit b5f2f939 authored by Federico Sismondi's avatar Federico Sismondi

Fix() for regex check on valid orion chars

parent 88782d76
......@@ -54,14 +54,14 @@ def get_ngsiv2_typed_description(val):
elif isinstance(val, int) or isinstance(val, float):
return {'type': 'Number', 'value': val}
elif isinstance(val, str):
# do some special chars cleaning
special_chars = ["'", "(", ")", "{", "}", "|"]
unaccented_comment = unidecode.unidecode(val)
for ch in special_chars:
unaccented_comment = unaccented_comment.replace(ch, "")
app.logger.warning("Special char deleted. This <{}> turned into this <{}>".format(val,unaccented_comment))
return {'type': 'Text', 'value': unaccented_comment}
pat=r'[<>"\'=;()]' # see https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html
r = re.compile(pat)
if r.search(val) is None:
new_val = val
else:
new_val = re.sub(pat, '',val)
app.logger.warning("Special char(s) deleted. This <{}> turned into this <{}>".format(val,new_val))
return {'type': 'Text', 'value': new_val}
elif isinstance(val, datetime.datetime):
# replace +00:00 is the same as Z but Orion doesnt like it :/
return {'type': 'DateTime', 'value': str(val.isoformat()).replace("+00:00", "Z")}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment