WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#36586 closed defect (bug) (fixed)

IXR_Value::isStruct() returns incorrectly for some arrays

Reported by: dd32 Owned by: ocean90
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: XML-RPC Keywords: has-unit-tests
Focuses: Cc:

Description

Running the following code will result in a fatal error:

$value = new IXR_Value( array( '0.0' => 100 ) );
echo $value->getXML();

This doesn't apply to a case such as [ '0.0' => 1, 'two' => 2 ] or [ 'one', 'others' => 3 ], only when an array has a single 0.0 key.

The issue is that IXR_Value::isStruct() detects this as a numerically indexed array, which it isn't.

The fix is simple, replacing != with !== so that "0.0" !== "0" is truthful, so that it detects it as a struct (a non-numeric array).

Another option is to replace it with a call to wp_is_numeric_array(), but since this is an external it makes sense to just make the single-character change.

Unfortunately I can't find the upstream to submit this to, other than contacting incutio directly and none of the recent forks appear to add anything of value.

Attachments (1)

36586.patch (690 bytes) - added by aaires 4 years ago.
Unit Test for 36586

Download all attachments as: .zip

Change History (4)

#1 @dd32
5 years ago

In 37244:

IXR: Use a strict comparison to ensure that a non-numerically-indexed array is not incorrectly matched as a numeric array.

See #36586

@aaires
4 years ago

Unit Test for 36586

#2 @aaires
4 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

I've added a unit test proposal for this issue under tests/xmlrpc/basic.php

#3 @ocean90
4 years ago

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

In 37980:

XML-RPC: Add unit test to verify IXR changes in [37244].

Props aaires.
Fixes #36586.

Note: See TracTickets for help on using tickets.