WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 18 months ago

Last modified 17 months ago

#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)

#1 @TimothyBlynJacobs
20 months ago

  • Milestone changed from Awaiting Review to 5.5

#2 @sorenbronsted
18 months ago

I will work on this

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


18 months ago

Added minLength and maxLength validation on strings

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

#4 @sorenbronsted
18 months ago

  • Keywords has-patch has-unit-tests added

#5 @TimothyBlynJacobs
18 months 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
18 months ago

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

#7 @prbot
18 months ago

sorenbronsted commented on PR #228:

New patch is coming up.

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


18 months ago

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.


18 months ago

Props sorenbronsted.
Fixes #48820.

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

#10 @TimothyBlynJacobs
18 months 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.

#11 @prbot
18 months ago

TimothyBJacobs commented on PR #238:

Merged in 86cbde3.

#12 @prbot
18 months ago

TimothyBJacobs commented on PR #230:

Thanks for the PR @sorenbronsted!

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

#13 @TimothyBlynJacobs
17 months 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.