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

Bad UTF-8 handling for NTriple parser #400

Closed
Arthur-VaisseLesteven opened this issue Jun 12, 2014 · 4 comments
Closed

Bad UTF-8 handling for NTriple parser #400

Arthur-VaisseLesteven opened this issue Jun 12, 2014 · 4 comments
Labels
bug Something isn't working enhancement New feature or request parsing Related to a parsing.
Milestone

Comments

@Arthur-VaisseLesteven
Copy link

The current NTriple parser does not handle properly utf-8 string.

the following triple trigger an error :
<http://linkedgeodata.org/triplify/user22701> <http://www.w3.org/2000/01/rdf-schema#label> "CiaránMooney" .

when executing this code :

line = codecs.open("file", "r", "utf-8").readline()
parser = NTriples.NTriplesParser(sink = mySink)
parser.parsestring(line)#where line is the previous triple

The parser fail to parse the "á" character.
Modifying the parse function of the NTriplesParser class allow to solve this bug.

Current :

  def parse(self, f):
        """Parse f as an N-Triples file."""
        if not hasattr(f, 'read'):
            raise ParseError("Item to parse must be a file-like object.")

        f = ascii(f)
        ...

Fix:

  def parse(self, f):
        """Parse f as an N-Triples file."""
        if not hasattr(f, 'read'):
            raise ParseError("Item to parse must be a file-like object.")

        f = codecs.getreader("utf-8")(f)
        ...

Hope this help.

AVL

@joernhees
Copy link
Member

i think this problem exists because the old N-Triples spec did not allow utf-8 encoding (but used 7bit ascii + \u... escapes): http://www.w3.org/2001/sw/RDFCore/ntriples/

RDF 1.1 changed this: http://www.w3.org/TR/n-triples/#n-triples-mediatype

question here is if someone still wants the old N-Triples behavior (e.g., for legacy reasons)... should we make this configurable? or maybe just on serialization?

@wojtasskorcz
Copy link

Are there any plans to resolve this issue in the near future? I have the same problem as @Arthur-VaisseLesteven

@gromgull
Copy link
Member

I am afraid I have no time for rdflib atm, but pull-requests are welcome!

@indeyets
Copy link

@joernhees new spec seems to be backwards compatible in terms of parsing, so I don't think there's any reason to avoid implement it. serialization is a whole different story, though. it should have a flag for emitting old-style files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request parsing Related to a parsing.
Projects
None yet
Development

No branches or pull requests

5 participants