#48820 closed enhancement (fixed)
Add additional string validation keywords to rest_validate_value_from_schema
Reported by: | TimothyBlynJacobs | Owned by: | TimothyBlynJacobs |
---|---|---|---|
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.
5 years ago
#3
Added minLength and maxLength validation on strings
Trac ticket: https://core.trac.wordpress.org/ticket/48820
#5
@
5 years 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.
sorenbronsted commented on PR #228:
5 years ago
#7
New patch is coming up.
This ticket was mentioned in PR #230 on WordPress/wordpress-develop by sorenbronsted.
5 years ago
#8
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.
5 years ago
#9
Props sorenbronsted.
Fixes #48820.
Trac ticket: https://core.trac.wordpress.org/ticket/48820
#10
@
5 years ago
- Owner set to TimothyBlynJacobs
- Resolution set to fixed
- Status changed from new to closed
In 47627:
TimothyBJacobs commented on PR #238:
5 years ago
#11
Merged in 86cbde3.
TimothyBJacobs commented on PR #230:
5 years ago
#12
Thanks for the PR @sorenbronsted!
Merged in 86cbde3 with some changes to be consistent with our other validation checks.
I will work on this