[wp-trac] [WordPress Trac] #57312: pattern validation fails in case of multitype validation using WP JSON REST

WordPress Trac noreply at wordpress.org
Sun Dec 11 14:55:22 UTC 2022


#57312: pattern validation fails in case of multitype validation using WP JSON REST
--------------------------+-----------------------------
 Reporter:  joeyojoeyo12  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Just as this https://core.trac.wordpress.org/ticket/56483 question for
 which I'm still waiting for a reply; I seemingly found another issue when
 trying to validate the input via oneOf. Concretely, I'm trying to validate
 that an object has:

 - pattern properties
 - with values being either a '^none$' string or a an array of strings
 matching another regex, like '^[A-Z][a-z]{5}[0-9]$'.

 Try to submit your data via the js FormData API which holds an object that
 should validate against sth like this:


 {{{
 'my_data'    => [
                             'type'                 => 'object',
                             'patternProperties'    => [
                                 '$[a-z]{5}$' => [
                                     'type'        => [
                                         'array',
                                         'string'
                                     ],
                                     'pattern' => '^none$',
                                     'items'       => [
                                         'type'    => 'string',
                                         'pattern' =>
 '^[A-Z][a-z]{5}[0-9]$'
                                     ],
                                     'uniqueItems' => true,
                                     'required'    => true
                                 ]
                             ],
                             'additionalProperties' => false,
                             'minProperties'        => 1,
                             'required'             => true
                         ]
 }}}

 If you submit something like:


 {{{
 {
   "my_data":{
     "abcde":"none"
   }
 }
 }}}

 It will result in a Bad Request error, telling you that my_data[abcde]
 does not match with ^none$.

 I've tried to use enum = ['none'] instead of pattern => '^none$', which is
 when it also responds with a 400 Bad Request, saying that my_data[abcde]
 is not none.

 Seems like a bug?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57312>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list