RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.11k stars 547 forks source link

HextuplesParser could/should use json.loads with strict=False #2809

Open lu-pl opened 1 week ago

lu-pl commented 1 week ago

Running property-based tests on an application showed that certain literal values, e.g. "\x08" and "\x1f" get rejected by the hext parser, i.e. parsing fails with an json.decoder.JSONDecodeError.

I think the problem can be remedied by using the strict=False flag in plugins.parsers.hext.HextuplesParser._load_json_line (hext.py, line 34).

import json

data = '["_:Nc5eeb3ec48394ee6b8219ec7b3ea55b9", "https://predicate/e674011e-9fcb-0c07-a107-391243867e06", "\x08", "http://www.w3.org/2001/XMLSchema#string", "", ""]'

json.loads(data)                          # JSONDecodeError
json.loads(data, strict=False)   # loading successful