WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 9 months ago

Last modified 7 months ago

#51231 closed defect (bug) (fixed)

prepare_attributes_for_render should pass $attribute_name to rest_validate_value_from_schema

Reported by: bobbingwide Owned by: helen
Milestone: 5.6 Priority: normal
Severity: minor Version: 5.5
Component: Editor Keywords: commit
Focuses: rest-api Cc:

Description

I accidentally discovered an error in my code where the attribute type for a server side rendered block was set to 'string ' - with an unexpected trailing space before the closing quote.

The doing_it_wrong message didn't tell me the name of the attribute that was in error.

Notice: rest_validate_value_from_schema was called incorrectly. 
The "type" schema keyword for can only be one of the built-in types: 
array, object, string, number, integer, boolean and null. 
Please see Debugging in WordPress for more information. 
(This message was added in version 5.5.0.) 
in C:\apache\htdocs\oikcom\wp-includes\functions.php on line 5225

Had it said:

The "type" schema keyword for until can only be one of the built-in types:

then I might have found the problem a bit quicker.

The fix would be to change prepare_attributes_for_render to pass the $attribute_name as the third parameter to rest_validate_value_from_schema.

$is_valid = rest_validate_value_from_schema( $value, $schema , $attribute_name );

Also correct the spelling of vebatim - to verbatim.

Attachments (1)

51231.diff (1.0 KB) - added by bobbingwide 9 months ago.
TRAC 51231 - pass $attribute_name to rest_validate_value_from_schema. Correct typo for verbatim

Download all attachments as: .zip

Change History (7)

@bobbingwide
9 months ago

TRAC 51231 - pass $attribute_name to rest_validate_value_from_schema. Correct typo for verbatim

#1 @TimothyBlynJacobs
9 months ago

  • Focuses rest-api added
  • Keywords commit added

This looks great to me, thanks for the patch @bobbingwide!

#2 @TimothyBlynJacobs
9 months ago

  • Milestone changed from Awaiting Review to 5.6

This ticket was mentioned in Slack in #core by helen. View the logs.


9 months ago

#4 @helen
9 months ago

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

In 48969:

REST API: Include attribute name in schema validation error message.

Props bobbingwide.
Fixes #51231.

#5 @auxjoel
7 months ago

I changed this line 230 in my class-wp-block-type.php file to be:
$is_valid = rest_validate_value_from_schema( $value, $schema, $attribute_name );

but I am still receiving the error. Is there any thing else I adjust?

#6 @helen
7 months ago

@auxjoel Could you explain the error you are receiving? This change is to provide more information with an error message, not avoid it.

Note: See TracTickets for help on using tickets.