Skip to content

Commit

Permalink
Add a is_string check to the params iterator (woocommerce#52361)
Browse files Browse the repository at this point in the history
This works fine:

```
curl -u bor0:asdf -X OPTIONS "localhost:8080/wp-json/wc/store/v1/products?_unstable_tax_asdf_operator=1" | jq
```

However, this causes a fatal error `PHP Fatal error:  Uncaught TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, int given`:

```
curl -u bor0:asdf -X OPTIONS "localhost:8080/wp-json/wc/store/v1/products?1=2" | jq
```
  • Loading branch information
bor0 authored Oct 28, 2024
1 parent 0b56f7e commit 1f0dc7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/fix-fatal-error-storeapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix StoreAPI erroring when a param is an integer
4 changes: 4 additions & 0 deletions plugins/woocommerce/src/StoreApi/Routes/V1/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ public function get_collection_params() {

// If the $_REQUEST contains a taxonomy query, add it to the params and sanitize it.
foreach ( $_REQUEST as $param => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! is_string( $param ) ) {
continue;
}

if ( str_starts_with( $param, '_unstable_tax_' ) && ! str_ends_with( $param, '_operator' ) ) {
$params[ $param ] = array(
'description' => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce' ),
Expand Down

0 comments on commit 1f0dc7a

Please sign in to comment.