#48820 closed enhancement (fixed)
Add additional string validation keywords to rest_validate_value_from_schema
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
I think it'd be helpful to add the minLength
and maxLength
JSON Schema validation keywords. https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.3.1
Change History (13)
This ticket was mentioned in PR #228 on WordPress/wordpress-develop by sorenbronsted.
12 months ago
Added minLength and maxLength validation on strings
Trac ticket: https://core.trac.wordpress.org/ticket/48820
#5
@
12 months ago
Thanks for working on this @sorenbronsted!
Something we need to be careful about is how we are measuring the length of a string. From the RFC:
The length of a string instance is defined as the number of its characters as defined by RFC 8259.
So we need to make sure that the way string length is measured would follow that RFC.
Additionally, it should probably be consistent with JavaScript based JSON Schema validators. I think checking for parity with ajv would be a good idea and maybe others as well.
The strings to pay attention to would be things like emoji. From what I can tell, an emoji should be counted as a single character.
- https://github.com/json-schema-org/json-schema-spec/issues/215#issuecomment-318156801
- https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/master/tests/draft7/minLength.json
- https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#keywords-for-strings
This means we should probably be using mb_strlen
.
Let's make sure we have tests that cover the same things in the JSON Schema Test Suite as well.
#7
@
12 months ago
sorenbronsted commented on PR #228:
New patch is coming up.
This ticket was mentioned in PR #230 on WordPress/wordpress-develop by sorenbronsted.
12 months ago
Added feedback from Timothy
Trac ticket: https://core.trac.wordpress.org/ticket/48820
This ticket was mentioned in PR #238 on WordPress/wordpress-develop by TimothyBJacobs.
12 months ago
Props sorenbronsted.
Fixes #48820.
Trac ticket: https://core.trac.wordpress.org/ticket/48820
#10
@
12 months ago
- Owner set to TimothyBlynJacobs
- Resolution set to fixed
- Status changed from new to closed
In 47627:
#11
@
12 months ago
TimothyBJacobs commented on PR #238:
Merged in 86cbde3.
#12
@
12 months ago
TimothyBJacobs commented on PR #230:
Thanks for the PR @sorenbronsted!
Merged in 86cbde3 with some changes to be consistent with our other validation checks.
I will work on this