Skip to content

Commit

Permalink
Merge pull request #1 from ravenscroftj/master
Browse files Browse the repository at this point in the history
Add escape for backslashes
  • Loading branch information
srinivasanthangavelu19 authored Sep 25, 2019
2 parents 996766d + 0ecbcbe commit 1e3e0f5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions surf/plugin/sparql_protocol/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _escape_string(value):
value = value.replace("\n"," ")
value = value.replace('\\"',':magicquote:').replace('"','\\"').replace(':magicquote:','\\"')
#value = value.replace("\\'",':magicquote:').replace("'","\\'").replace(':magicquote:',"\\'")
value = value.replace('\\',':doubleslash:').replace("\\","\\\\").replace(":doubleslash:","\\")
value = value.replace('\\\\',':doubleslash:').replace("\\","\\\\").replace(":doubleslash:","\\\\")

return value

Expand All @@ -84,7 +84,7 @@ def _prepare_add_many_query(resources, context=None):
for p, objs in list(resource.rdf_direct.items()):
for o in objs:

if isinstance(o, Literal) and isinstance(o.value, str) and ("'" in o.value or '"' in o.value):
if isinstance(o, Literal) and isinstance(o.value, str) and ("'" in o.value or '"' in o.value or '\\'):
o = Literal(_escape_string(o.value), datatype=o.datatype)

query.template((s, p, o))
Expand Down

0 comments on commit 1e3e0f5

Please sign in to comment.