Skip to content
This repository was archived by the owner on Jun 15, 2022. It is now read-only.

Commit f178687

Browse files
committed
Properly escape the LIKE comparison in search_orders()
1 parent 765dc50 commit f178687

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

includes/class-wc-order-data-store-custom-table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,9 @@ public function search_orders( $term ) {
582582
$wpdb->prepare( "
583583
SELECT order_id
584584
FROM {$wpdb->prefix}woocommerce_order_items as order_items
585-
WHERE order_item_name LIKE '%%%s%%'
585+
WHERE order_item_name LIKE %s
586586
",
587-
$term
587+
'%' . $wpdb->esc_like( $term ) . '%'
588588
)
589589
)
590590
) );

tests/test-data-store.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ public function test_search_orders_checks_table_for_product_item_matches() {
141141
);
142142
}
143143

144+
public function test_search_orders_checks_table_for_product_item_matches_with_like_comparison() {
145+
$product = $this->factory()->product->create_and_get( array(
146+
'post_title' => 'foo bar baz',
147+
) );
148+
$order = $this->factory()->order->create_and_get();
149+
$order->add_product( $product );
150+
$order->save();
151+
152+
$this->assertEquals(
153+
array( $order->get_id() ),
154+
( new WC_Order_Data_Store_Custom_Table() )->search_orders( 'bar' ),
155+
'Product items should be searched using a LIKE comparison and wildcards.'
156+
);
157+
}
158+
144159
/**
145160
* @dataProvider order_type_provider()
146161
*/

0 commit comments

Comments
 (0)