Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#48820 closed enhancement (fixed)

Add additional string validation keywords to rest_validate_value_from_schema

Reported by: timothyblynjacobs's profile TimothyBlynJacobs Owned by: timothyblynjacobs's profile 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)

#1 @TimothyBlynJacobs
4 years ago

  • Milestone changed from Awaiting Review to 5.5

#2 @sorenbronsted
4 years ago

I will work on this

This ticket was mentioned in PR #228 on WordPress/wordpress-develop by sorenbronsted.


4 years ago
#3

Added minLength and maxLength validation on strings

Trac ticket: https://core.trac.wordpress.org/ticket/48820

#4 @sorenbronsted
4 years ago

  • Keywords has-patch has-unit-tests added

#5 @TimothyBlynJacobs
4 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.

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.

#6 @sorenbronsted
4 years ago

@TimothyBlynJacobs Thanks for your excellent feedback. I will fix this.

sorenbronsted commented on PR #228:


4 years ago
#7

New patch is coming up.

This ticket was mentioned in PR #230 on WordPress/wordpress-develop by sorenbronsted.


4 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.


4 years ago
#9

Props sorenbronsted.
Fixes #48820.

Trac ticket: https://core.trac.wordpress.org/ticket/48820

#10 @TimothyBlynJacobs
4 years ago

  • Owner set to TimothyBlynJacobs
  • Resolution set to fixed
  • Status changed from new to closed

In 47627:

REST API: Support the (min|max)Length JSON Schema keywords.

Props sorenbronsted.
Fixes #48820.

TimothyBJacobs commented on PR #238:


4 years ago
#11

Merged in 86cbde3.

TimothyBJacobs commented on PR #230:


4 years ago
#12

Thanks for the PR @sorenbronsted!

Merged in 86cbde3 with some changes to be consistent with our other validation checks.

#13 @TimothyBlynJacobs
4 years ago

In 47811:

REST API: Add @since entries for rest_validate_value_from_schema().

See #49572, #48818, #44949, #50053, #48820, #49720, #42961, #44975, #43392, #38583.

Note: See TracTickets for help on using tickets.