Skip to content

Check for keys in term definition outside that expected #214

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

Merged
merged 2 commits into from
Jan 19, 2018

Conversation

gkellogg
Copy link
Collaborator

@container, @id, @language, @reverse, and @type. This also sets up for additional keywords in 1.1.

…, `@id`, `@language`, `@reverse`, and `@type`. This also sets up for additional keywords in 1.1.
@gkellogg gkellogg added this to the v0.5.0 milestone Jan 14, 2018
@gkellogg
Copy link
Collaborator Author

This, or something similar, should probably be part of 0.5.x, as it was a hole in the 1.0 spec that we did not check for extra keywords in a term definition. That said, it perhaps should be something short of an error, or check for some weaker mode. It could also constrain itself to only look for things that start with @, so that something like "comment" could be used. Same could be true elsewhere in the context.

lib/context.js Outdated
@@ -442,6 +460,10 @@ api.createTermDefinition = (activeCtx, localCtx, term, defined) => {
mapping['@language'] = language;
}

if('@next' in value) {

}
Copy link
Member

Choose a reason for hiding this comment

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

Missing something here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should have been removed, and should have been @nest for a different branch.

@davidlehn
Copy link
Member

Is this covered in 1.1 spec and/or the test suite? Not sure what the compatibility story is for such changes.

I'm fine adding more checks though at some point we'll want to profile the code and put such things behind flags if needed so there can be a fast mode for known correct data.

@gkellogg
Copy link
Collaborator Author

1.0 did not require such checks, which is why we needed to add @version. Adding it for a 1.1 processor that is running in 1.0 mode allows it to find such issues, and of course, to do appropriate checks in 1.1 mode as well.

@davidlehn
Copy link
Member

Won't this always run in both 1.0 and 1.1 modes? Just worried about the edge case of 1.0 input with bogus keys that used to be processed but now fails.

@gkellogg
Copy link
Collaborator Author

It's true that an old processor would process invalid term definition and container keys and not report an error, but this should be considered a bug, IMHO, even though the 1.0 spec did not call it out. It's a feature that an updated processor, in 1.0 mode, will find such problems, and it enhances forward compatibility; if we had done this, we wouldn't need @version announcement.

There are a couple of other cases where the new spec causes a processor running in 1.0 mode to be have differently, for example, compact IRI selection of appropriate terms to use for prefixes.

Your call; my processor performs this test in 1.0, and I've not seen any reported issues. If you don't do this, and someone runs through the playground using new features, but without being in 1.1 mode, they could be confused about why output isn't as expected, which would be a worse problem then people using bad contexts now that report an error.

An alternative, if you have the capability, would be to make it a softer error/warning, and allow a string or validation mode which would make it a hard error.

@davidlehn
Copy link
Member

I'm fine with better checks going forward. Are there test suite tests for this? Would be good to have them so at least all implementations do the same thing. I don't think we have a warning system yet. The compactionMap/expansionMap callback-like api options are close though. But in cases like this probably better to just bail for problems.

@gkellogg
Copy link
Collaborator Author

There is one test on the use of @prefix in 1.0 (error-p007); there should be checks for @context and @nest as well.

Similarly, there are not, and should be 1.0 tests to make sure @container can't be an array, and can't include @graph, @id or @type. I'll take care of getting these added as part of this PR.

@gkellogg
Copy link
Collaborator Author

@gkellogg gkellogg mentioned this pull request Jan 19, 2018
@davidlehn davidlehn merged commit af2eee9 into 0.5.x Jan 19, 2018
@davidlehn davidlehn deleted the check-td-keys branch January 19, 2018 02:25
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

Successfully merging this pull request may close these issues.

3 participants