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

further specify the format of iri-references throughout #1085

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions meta/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"type": ["object", "boolean"],
"properties": {
"$id": {
"$ref": "#/$defs/iriReferenceString",
"type": "string",
"format": "iri-reference",
"$comment": "Non-empty fragments not allowed.",
"pattern": "^[^#]*#?$"
},
"$schema": { "$ref": "#/$defs/iriString" },
"$ref": { "$ref": "#/$defs/iriReferenceString" },
"$ref": { "$ref": "#/$defs/iriReferenceToSchemaString" },
"$anchor": { "$ref": "#/$defs/anchorString" },
"$dynamicRef": { "$ref": "#/$defs/iriReferenceString" },
"$dynamicRef": { "$ref": "#/$defs/iriReferenceToSchemaString" },
"$dynamicAnchor": { "$ref": "#/$defs/anchorString" },
"$vocabulary": {
"type": "object",
Expand All @@ -43,9 +44,11 @@
"type": "string",
"format": "iri"
},
"iriReferenceString": {
"iriReferenceToSchemaString": {
"type": "string",
"format": "iri-reference"
"format": "iri-reference",
"$comment": "any fragment must be empty, or match anchor or json-pointer syntax",
"pattern": "^[^#]*(#([A-Za-z_][-A-Za-z0-9.:_]*|/([^~]|~[01])*))?$"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"pattern": "^[^#]*(#([A-Za-z_][-A-Za-z0-9.:_]*|/([^~]|~[01])*))?$"
"pattern": "^[^#]*(#([A-Za-z_][-A-Za-z0-9.:_]*|(/([^~/]|~[01])*)*))?$"

The second half of the fragment match, for JSON Pointer, won't match the empty pointer ($ref: "#", $ref: "foo#"). The suggested change follows the JSON Pointer ABNF.

This is still incomplete though. Fragments may contain %xx encoded characters. In a pointer their use may be necessary, but in either a pointer or anchor they are expected to be treated like the characters they represent, even when those characters don't actually need to be %-encoded.

Suggested change
"pattern": "^[^#]*(#([A-Za-z_][-A-Za-z0-9.:_]*|/([^~]|~[01])*))?$"
"pattern": "^[^#]*(#(([A-Za-z_]|%[A-Fa-f0-9]{2})([-A-Za-z0-9.:_]|%[A-Fa-f0-9]{2})*|((/|%2[fF])([^~/%]|~[01]|%[A-Fa-f0-9]{2})*)*))?$"

Not too pretty, but I think it allows anything that's valid. It won't reject some invalid anchors or pointers if they're %-encoded - it would be possible to express the same character ranges as allowed combinations of %-encoded digits, but I'm not masochistic enough to do it.

I'm a little uncertain describing a uri fragment with a regex isn't more trouble than it's worth.

}
}
}
4 changes: 3 additions & 1 deletion output/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
},
"absoluteKeywordLocation": {
"type": "string",
"format": "uri"
"format": "iri",
"$comment": "any fragment must be non-empty, and use json-pointer syntax",
"pattern": "^[^#]*(#(/([^~]|~[01])*)*)?$"
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment says must be non-empty, but this does allow an empty fragment.

Suggested change
"pattern": "^[^#]*(#(/([^~]|~[01])*)*)?$"
"pattern": "^[^#]*(#(/([^~/]|~[01])*)+)?$"

The change to + requires a non-empty pointer; disallowing the / from the reference-token character range is better consistent with its spec's ABNF (and iriReferenceToSchemaString above), though it doesn't ultimately change what the regex matches.

And of course %-encoding needs fixing here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

actually I think we need to allow empty fragments, so it's the comment that is wrong here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@karenetheridge Agreed, you need to be able to represent the root with a JSON Pointer fragment, which would be an empty fragment.

},
"instanceLocation": {
"type": "string",
Expand Down
3 changes: 1 addition & 2 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
},
"$recursiveRef": {
"$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
"type": "string",
"format": "uri-reference",
"$ref": "meta/core#/$defs/iriReferenceToSchemaString",
"deprecated": true
}
}
Expand Down