Commit 422967230bc for woocommerce

commit 422967230bc6d129eda16a7745f69c75a8266817
Author: iris-woocommerce[bot] <282076412+iris-woocommerce[bot]@users.noreply.github.com>
Date:   Thu Dec 3 07:57:23 2026 +0100

    Stop product-attributes-query search from matching every attribute for pa, a_ or _ (#71656)

    * Match product attributes query search against the slug without pa_

    Co-authored-by: matticbot <matticbot@users.noreply.github.com>

    * Clarify product attributes query search description and fix test lint

    Describe that search matches the unprefixed slug and that taxonomy-name
    searches need pa_ plus part of the slug. Split the test fixture array
    onto one entry per line to satisfy phpcs.

    Co-authored-by: aaronfc <yo@aaron.com.es>
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Match product attribute searches against the taxonomy name unless part of pa_

    Only skip the taxonomy-name check when the search is a fragment of the
    pa_ prefix, so fragments such as _c still find pa_color. Simplify the
    search schema description and cover a prefix-crossing fragment and misses.

    Co-authored-by: chr-hertel
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---------

    Co-authored-by: aaronfc <aaron.fas@automattic.com>
    Co-authored-by: matticbot <matticbot@users.noreply.github.com>
    Co-authored-by: aaronfc <yo@aaron.com.es>
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/fix-product-attributes-query-search-prefix b/plugins/woocommerce/changelog/fix-product-attributes-query-search-prefix
new file mode 100644
index 00000000000..4f90b374bdf
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-product-attributes-query-search-prefix
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Stop short searches such as "pa" or "_" in the product attributes query ability from matching every attribute.
diff --git a/plugins/woocommerce/src/Internal/Abilities/Domain/ProductAttributesQuery.php b/plugins/woocommerce/src/Internal/Abilities/Domain/ProductAttributesQuery.php
index df096b2128e..ad51f3dcbba 100644
--- a/plugins/woocommerce/src/Internal/Abilities/Domain/ProductAttributesQuery.php
+++ b/plugins/woocommerce/src/Internal/Abilities/Domain/ProductAttributesQuery.php
@@ -99,11 +99,13 @@ class ProductAttributesQuery extends AbstractDomainAbility implements AbilityDef

 		$search = trim( $input['search'] ?? '' );
 		if ( '' !== $search ) {
+			// A search that is part of `pa_` would match every taxonomy name, so it only checks the label and stored slug.
 			$attributes = array_values(
 				array_filter(
 					$attributes,
 					static fn( $attribute ) => false !== stripos( (string) $attribute->attribute_label, $search )
-						|| false !== stripos( wc_attribute_taxonomy_name( (string) $attribute->attribute_name ), $search )
+						|| false !== stripos( (string) $attribute->attribute_name, $search )
+						|| ( false === stripos( 'pa_', $search ) && false !== stripos( wc_attribute_taxonomy_name( (string) $attribute->attribute_name ), $search ) )
 				)
 			);
 		}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributesQueryTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributesQueryTest.php
index e6d1758fb77..632903bcf34 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributesQueryTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributesQueryTest.php
@@ -150,6 +150,50 @@ class ProductAttributesQueryTest extends WC_Unit_Test_Case {
 		$this->assertSame( array( 'Test Pattern' ), wp_list_pluck( $page['attributes'], 'name' ), 'Attributes are sorted by slug.' );
 	}

+	/**
+	 * @testdox Should not match every attribute when the search is part of the pa_ prefix, such as pa, a_ or _.
+	 */
+	public function test_search_ignores_the_taxonomy_prefix(): void {
+		$ids        = array();
+		$attributes = array(
+			'color'       => 'Color',
+			'garment-fit' => 'Fit',
+			'pattern'     => 'Pattern',
+			'spa_size'    => 'Spa Size',
+		);
+		foreach ( $attributes as $slug => $name ) {
+			$ids[] = wc_create_attribute(
+				array(
+					'name' => $name,
+					'slug' => $slug,
+				)
+			);
+		}
+		$search = fn( string $search ) => $this->sut->execute(
+			array(
+				'include' => $ids,
+				'search'  => $search,
+			)
+		);
+
+		$expected = array(
+			'pa'     => array( 'Pattern', 'Spa Size' ),
+			'a_'     => array( 'Spa Size' ),
+			'_'      => array( 'Spa Size' ),
+			'pa_'    => array( 'Spa Size' ),
+			'MENT-F' => array( 'Fit' ),
+			'PA_SPA' => array( 'Spa Size' ),
+			'_c'     => array( 'Color' ),
+			'pa_xyz' => array(),
+			'xyz'    => array(),
+		);
+		foreach ( $expected as $query => $names ) {
+			$result = $search( $query );
+			$this->assertSame( $names, wp_list_pluck( $result['attributes'], 'name' ), $query );
+			$this->assertSame( count( $names ), $result['total'], $query );
+		}
+	}
+
 	/**
 	 * @testdox Should return the product_term extension fields on each term, as product-terms-query does, and prime the terms of all attributes once.
 	 */