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 a KeyError in N-Quads normalization #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/pyld/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ def to_nquad(triple, graph_name=None):
.replace('\"', '\\"'))
quad += '"' + escaped + '"'
if o['datatype'] == RDF_LANGSTRING:
if o['language']:
if o.get('language'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if 'language' in o:?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what this check is actually for, but o['language'] is assuming the key exists and testing whether its value is falsy, which is why I changed it to o.get('language'), which is also falsy (None) if the key doesn't exist.

'language' in o would test only whether the key exists, which is orthogonal to what it was doing before. That doesn't necessarily mean it's wrong, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the discussion, it seems the PR should detect an incorrect form of the context. Currently, it will just ignore the issue.

quad += '@' + o['language']
elif o['datatype'] != XSD_STRING:
quad += '^^<' + o['datatype'] + '>'
Expand Down