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

Move test of \a regex character to optional/format/regex #740

Merged
merged 1 commit into from May 19, 2024

Conversation

notEthan
Copy link
Contributor

@notEthan notEthan commented Apr 18, 2024

This was validating "\a" as a schema pattern described by the meta-schema as format: regex. This moves it to directly test the pattern against a format: regex schema.

related: e42e8417, #309, json-schema-org/json-schema-spec#821

@notEthan notEthan requested a review from a team as a code owner April 18, 2024 20:12
@Julian
Copy link
Member

Julian commented Apr 21, 2024

This doesn't really seem correct to me. The regex file is often run by implementations using some other regex dialect, and in that other dialect \a very well may be a valid regular expression. The file these were in is the file meant to represent thing specific to ECMA regexes.

@karenetheridge
Copy link
Member

We already put format tests in optional/ because it's understood that full specification adherence is spotty. If the ECMA spec says that this string is a valid (or invalid) pattern, then it belongs in this file (optional/format/regex.json).

The test definitely does not belong where it is currently because formats are never invalid using the draft2020-12 metaschema dialect, because formats are only annotations there.

@notEthan
Copy link
Contributor Author

Reasons I think this test belongs where this PR moves it:

  • It's validating a property of a schema (pattern) against the meta-schema (specifying "format": "regex") but there's no reason the meta-schema needs to be involved in this, validating the pattern "\\a" directly against a "format": "regex" schema has the same effect.

  • The rest of the tests in ecmascript-regex.json are testing strings against a pattern, this is the only one testing a regex pattern against format: regex.

  • It shouldn't be doing any validation at all, in this context. The 2020-12 meta-schema uses the format-annotation vocabulary, not format-assertion - this doesn't mean it can't do validation, per:

    Implementations MAY still treat "format" as an assertion ... The implementation MUST provide options to enable and disable such evaluation and MUST be disabled by default. (ref)

    But there's nothing about this test that indicates that a non-default option to enable validation should be set. The tests in optional/format/regex.json (which also rely on validation behavior) also don't have any indication of that - which I think is another issue that warrants correction, possibly as part of Break out optional tests into requirement-level directories #708 - but at least they all consistently expect format validation, and this test having the same expectation makes sense in that context.

Discussed a few days ago with @karenetheridge on slack, for reference, though I think I've made the same points here. https://json-schema.slack.com/archives/C8CQ81GKF/p1713142486362639

@gregsdennis
Copy link
Member

there's no reason the meta-schema needs to be involved in this

We've recently decided that meta-schema tests are not really in scope for this suite.

validating the pattern "\\a" directly against a "format": "regex" schema has the same effect [and related]

The spec provides allowance to validate format, however the main portion of this suite is testing the requirements of the spec. Optional behaviors, which includes impromptu validation of format, need to go in the optional/ folder until we decide to merge that other break-out PR.

What I would be open to is creating a set of required format tests where the schemas have a custom dialect that includes the format-assertion vocab. However, even this has some variability in support: the spec says that implementations are to provide a "best effort" validation. (I stated it that way on purpose to alleviate the burden from maintainers.)

I agree with the changes proposed by this PR.

@Julian
Copy link
Member

Julian commented Apr 29, 2024

Those sound like good reasons to fix/modify the test, and not good reasons to move the test to me, but do as y'all wish.

@notEthan
Copy link
Contributor Author

notEthan commented May 6, 2024

This does modify the test, as well as moving it to a more appropriate location. I'm not sure what else would be more of an improvement.

@Julian
Copy link
Member

Julian commented May 6, 2024

It moves it to a strictly worse location, because it moves it from a file that is "tests for ECMA dialect regexes" to one that is not and is meant to be run across multiple possible regular expression dialects.

@notEthan
Copy link
Contributor Author

I can leave the test where it is - that part doesn't matter to my test harness, anyway - but do you agree that testing with "data": "\\a" against a schema with "format": "regex" - dropping the meta-schema in between - is correct?

I do still think it has more in common with optional/format/regex.json than optional/ecmascript-regex.json but you didn't really respond to the reasons I said - that's fine, if the test being \a's role in ECMA dialect outweighs what I said, I'm good accepting that. Let me know if you agree with the change to the test content and I will move it back where it was.

@Julian
Copy link
Member

Julian commented May 13, 2024

but do you agree that testing with "data": "\a" against a schema with "format": "regex" - dropping the meta-schema in between - is correct?

Yes.

but you didn't really respond to the reasons I said

Happy to do this, but then can you point me at which ones you mean here, I'm happy to respond, but none of the ones I saw had anything to do with where the test was located, which is exactly why I commented with what I did.

Let me know if you agree with the change to the test content and I will move it back where it was.

Yes I agree.

@Julian
Copy link
Member

Julian commented May 13, 2024

I mean I guess just to directly comment on each one since those are the only ones here:

It's validating a property of a schema (pattern) against the meta-schema (specifying "format": "regex") but there's no reason the meta-schema needs to be involved in this, validating the pattern "\a" directly against a "format": "regex" schema has the same effect.

This certainly doesn't seem to have anything to do with which file it belongs in to me.

The rest of the tests in ecmascript-regex.json are testing strings against a pattern, this is the only one testing a regex pattern against format: regex.

This seems like we simply haven't had any tests of an invalid regex, and now we do.

It shouldn't be doing any validation at all, in this context. The 2020-12 meta-schema uses the format-annotation vocabulary, not format-assertion - this doesn't mean it can't do validation, per:

This again seems to have nothing to do with what file it's in and simply is commenting on the test being wrong in 2020.

But there's nothing about this test that indicates that a non-default option to enable validation should be set. The tests in optional/format/regex.json (which also rely on validation behavior) also don't have any indication of that - which I think is another issue that warrants correction, possibly as part of
#708 - but at least they all consistently expect format validation, and this test having the same expectation makes sense in that context.

(This again doesn't have to do with what file the test is in though since you mention it, this is precisely why this test was fine in versions pre-2019 -- and why it's really a simple documentation issue for 2019 + 2020 at which point they'd be valid even where they are. But I'm honestly tired of that discussion, which is why it's easier to just say "sure change it".)

@notEthan notEthan force-pushed the format-pattern-control-char branch from 20d15a8 to cbd48ea Compare May 19, 2024 14:56
@notEthan
Copy link
Contributor Author

Thanks, Julian. I moved it back and rebased.

@Julian
Copy link
Member

Julian commented May 19, 2024

I didn't do anything but quibble really, no need to thank me :) but this lgtm now too.

@notEthan
Copy link
Contributor Author

I think you're right that it was fine where it is, and appreciate the time you took saying why.

@Julian
Copy link
Member

Julian commented May 19, 2024

Ok I'm gonna merge given it looks like others were already ok with this but if for whatever reason anyone thinks it was better before or something we can address.

Thanks again!

@Julian Julian merged commit 9fc880b into json-schema-org:main May 19, 2024
3 checks passed
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.

None yet

4 participants