[wp-trac] [WordPress Trac] #48820: Add additional string validation keywords to rest_validate_value_from_schema

WordPress Trac noreply at wordpress.org
Mon Apr 20 15:47:09 UTC 2020


#48820: Add additional string validation keywords to
rest_validate_value_from_schema
--------------------------------------+---------------------
 Reporter:  TimothyBlynJacobs         |       Owner:  (none)
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  5.5
Component:  REST API                  |     Version:  4.7
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------

Comment (by TimothyBlynJacobs):

 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
 [https://github.com/epoberezkin/ajv 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48820#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list