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

Improve @language and @direction safe mode checks. #541

Open
davidlehn opened this issue Nov 9, 2023 · 2 comments
Open

Improve @language and @direction safe mode checks. #541

davidlehn opened this issue Nov 9, 2023 · 2 comments

Comments

@davidlehn
Copy link
Member

If @language and/or @direction are incorrectly used as a regular properties, they appear in expanded output, but are silently dropped when converting to RDF quads. Determine if this should be a general error, general warning, safe mode error, or something else. May need main spec and/or test suite updates. May need to check if this happens with other keywords as well.

{
  "@language": "foo",
  "@direction": "rtl",
  "ex:a": "bar"
}
@BigBlueHat
Copy link
Contributor

@gkellogg would love your take on why this happens. Distiller throws an error, so it's likely a bug in jsonld.js (and therefore the JSON-LD Playground). I doubt it's something we could make use of in a JSON-LD 1.2--i.e. allowing the use of these for the document even when a context file is provided out of band. Would be kind of nice, though, potentially (assuming it's not a breaking change for all other JSON-LD libraries).

At any rate, knowing the right error to through here would help--as I couldn't sort that out from the processing spec.

@gkellogg
Copy link
Collaborator

The spec is silent on this. My implementation does generate an error when generating RDF, but it seems to be due to some other failed expectation, and not specifically looking for node objects which contain keywords only expected in value objects. The error is actually coming from the Node Map Generation algorithm, where it expects element to either be an array or a map, and keywords such as @language and direction are neither.

    elsif !element.is_a?(Hash)
      raise "Expected hash or array to create_node_map, got #{element.inspect}"

The algorithm doesn't say what to do if element is neither an array nor a map; my implementation raises an error. Looking at jsonld.js createNodeMap seems to generally just return at the same point.

jsonld.js/lib/nodeMap.js

Lines 56 to 61 in e2f6523

// add non-object to list
if(!types.isObject(input)) {
if(list) {
list.push(input);
}
return;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants