Skip to content

Commit db06a5c

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents f45238a + 082d382 commit db06a5c

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/wp-includes/class-wp-xmlrpc-server.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,9 @@ public function wp_editTerm( $args ) {
22132213
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
22142214
do_action( 'xmlrpc_call', 'wp.editTerm', $args, $this );
22152215

2216-
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) {
2216+
if ( ! isset( $content_struct['taxonomy'] )
2217+
|| ! taxonomy_exists( $content_struct['taxonomy'] )
2218+
) {
22172219
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
22182220
}
22192221

tests/phpunit/tests/xmlrpc/wp/editTerm.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,38 @@ public function test_invalid_taxonomy() {
5050
$this->assertSame( __( 'Invalid taxonomy.' ), $result->message );
5151
}
5252

53+
/**
54+
* Ensures a non-array content struct is rejected rather than causing a fatal error.
55+
*
56+
* When the content struct (the fifth argument) is passed as a string instead of a
57+
* struct, the method must return an error instead of attempting to access a string
58+
* offset, which triggers "Cannot access offset of type string on string" on PHP 8+.
59+
*
60+
* @ticket 65682
61+
*/
62+
public function test_invalid_content_struct_should_return_error() {
63+
$this->make_user_by_role( 'editor' );
64+
65+
$result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$parent_term, 'not-a-struct' ) );
66+
$this->assertIXRError( $result );
67+
$this->assertSame( 403, $result->code );
68+
$this->assertSame( __( 'Invalid taxonomy.' ), $result->message );
69+
}
70+
71+
/**
72+
* Ensures a missing content struct is rejected with an insufficient arguments error.
73+
*
74+
* @ticket 65682
75+
*/
76+
public function test_missing_content_struct_should_return_error() {
77+
$this->make_user_by_role( 'editor' );
78+
79+
$result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$parent_term ) );
80+
$this->assertIXRError( $result );
81+
$this->assertSame( 400, $result->code );
82+
$this->assertSame( __( 'Insufficient arguments passed to this XML-RPC method.' ), $result->message );
83+
}
84+
5385
public function test_incapable_user() {
5486
$this->make_user_by_role( 'subscriber' );
5587

0 commit comments

Comments
 (0)