[wp-trac] [WordPress Trac] #50189: Only validate format if type is string

WordPress Trac noreply at wordpress.org
Sat May 16 19:43:08 UTC 2020


#50189: Only validate format if type is string
-------------------------+-------------------------------------------------
 Reporter:               |      Owner:  (none)
  TimothyBlynJacobs      |
     Type:  defect       |     Status:  new
  (bug)                  |
 Priority:  normal       |  Milestone:  5.5
Component:  REST API     |    Version:  5.3
 Severity:  normal       |   Keywords:  needs-patch needs-unit-tests good-
  Focuses:  rest-api     |  first-bug json-schema
-------------------------+-------------------------------------------------
 In #44975 we added support for a schema to specify multiple types. The way
 this works is we iterate over each possible type and try to find a
 successful validation. This poses an issue if you are trying to use a
 schema with a string type and the format keyword. This is because the
 schema will try and apply the `format` validation even if it isn't
 checking against the string type.

 From the JSON Schema spec:

 > A format attribute can generally only validate a given set of instance
 types.  If the type of the instance to validate is not in this set,
 validation for this format attribute and instance SHOULD succeed.

 We should update `rest_validate_value_from_schema()` and
 `rest_sanitize_value_from_schema()` to only check against the `format`
 keyword if we are validating a string.

 This could be a BC break if a developer had omitted a type definition or
 misspelled it ( `strin` instead of `string` ). We could potentially
 account for this by also applying the check if there was no type set or it
 was invalid.

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


More information about the wp-trac mailing list