Loading CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Search API 1.x, dev (xxxx-xx-xx): --------------------------------- - #3257550 by drunken monkey, lpeidro: Fixed wrong handling of empty values in the HTML filter. - #3029582 by drunken monkey, RichardDavies: Fixed handling of Views contextual filters in combination with filter groups. - #3247840 by drunken monkey: Added a hidden datasource option to disable the Loading src/Processor/FieldsProcessorPluginBase.php +7 −4 Original line number Diff line number Diff line Loading @@ -326,8 +326,6 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements $type = $field->getType(); foreach ($values as $i => &$value) { // We restore the field's type for each run of the loop since we need the // unchanged one as long as the current field value hasn't been updated. if ($value instanceof TextValueInterface) { $tokens = $value->getTokens(); if ($tokens !== NULL) { Loading @@ -352,13 +350,18 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements } } } if ($new_tokens === []) { unset($values[$i]); } else { $value->setTokens($new_tokens); } } else { $text = $value->getText(); if ($text !== '') { $this->processFieldValue($text, $type); if ($text === '') { if ($text === '' || $text === []) { unset($values[$i]); } elseif (is_scalar($text)) { Loading @@ -373,7 +376,7 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements elseif ($value !== '') { $this->processFieldValue($value, $type); if ($value === '') { if ($value === '' || $value === []) { unset($values[$i]); } } Loading tests/src/Unit/Processor/HtmlFilterTest.php +41 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Drupal\Tests\search_api\Unit\Processor; use Drupal\search_api\IndexInterface; use Drupal\search_api\Item\Field; use Drupal\search_api\Plugin\search_api\data_type\value\TextToken; use Drupal\search_api\Plugin\search_api\data_type\value\TextValue; use Drupal\search_api\Plugin\search_api\processor\HtmlFilter; use Drupal\search_api\Query\Condition; use Drupal\search_api\Utility\Utility; Loading Loading @@ -33,7 +35,7 @@ class HtmlFilterTest extends UnitTestCase { } /** * Tests preprocessing field values with "title" settings. * Tests preprocessing field values with different "title" settings. * * @param string $passed_value * The value that should be passed into process(). Loading Loading @@ -75,7 +77,7 @@ class HtmlFilterTest extends UnitTestCase { } /** * Tests preprocessing field values with "alt" settings. * Tests preprocessing field values with different "alt" settings. * * @param string $passed_value * The value that should be passed into process(). Loading Loading @@ -151,7 +153,7 @@ class HtmlFilterTest extends UnitTestCase { } /** * Tests preprocessing field values with "alt" settings. * Tests preprocessing field values with different "tags" settings. * * @param string $passed_value * The value that should be passed into process(). Loading Loading @@ -305,4 +307,40 @@ class HtmlFilterTest extends UnitTestCase { $this->assertSame([$condition], $conditions); } /** * Tests empty values handling. * * @see https://www.drupal.org/project/search_api/issues/3212925 */ public function testEmptyValueHandling() { $index = $this->createMock(IndexInterface::class); $field = (new Field($index, 'field')) ->setType('text'); $index->method('getFields')->willReturn([ 'field' => $field, ]); $field->setValues([new TextValue('<p></p>')]); $this->invokeMethod('processField', [$field]); $this->assertEquals([], $field->getValues()); $value = new TextValue('<p></p>'); $value->setTokens([new TextToken('<p></p>')]); $field->setValues([$value]); $this->invokeMethod('processField', [$field]); $this->assertEquals([], $field->getValues()); // In theory, setting the value of a "text" field to a string instead of a // TextValue object is not allowed, but when it happens we might as well // handle it graciously (though other parts of the framework might not). $field->setValues(['<p></p>']); $this->invokeMethod('processField', [$field]); $this->assertEquals([], $field->getValues()); $field->setType('string'); $field->setValues(['<p></p>']); $this->invokeMethod('processField', [$field]); $this->assertEquals([], $field->getValues()); } } Loading
CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Search API 1.x, dev (xxxx-xx-xx): --------------------------------- - #3257550 by drunken monkey, lpeidro: Fixed wrong handling of empty values in the HTML filter. - #3029582 by drunken monkey, RichardDavies: Fixed handling of Views contextual filters in combination with filter groups. - #3247840 by drunken monkey: Added a hidden datasource option to disable the Loading
src/Processor/FieldsProcessorPluginBase.php +7 −4 Original line number Diff line number Diff line Loading @@ -326,8 +326,6 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements $type = $field->getType(); foreach ($values as $i => &$value) { // We restore the field's type for each run of the loop since we need the // unchanged one as long as the current field value hasn't been updated. if ($value instanceof TextValueInterface) { $tokens = $value->getTokens(); if ($tokens !== NULL) { Loading @@ -352,13 +350,18 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements } } } if ($new_tokens === []) { unset($values[$i]); } else { $value->setTokens($new_tokens); } } else { $text = $value->getText(); if ($text !== '') { $this->processFieldValue($text, $type); if ($text === '') { if ($text === '' || $text === []) { unset($values[$i]); } elseif (is_scalar($text)) { Loading @@ -373,7 +376,7 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements elseif ($value !== '') { $this->processFieldValue($value, $type); if ($value === '') { if ($value === '' || $value === []) { unset($values[$i]); } } Loading
tests/src/Unit/Processor/HtmlFilterTest.php +41 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Drupal\Tests\search_api\Unit\Processor; use Drupal\search_api\IndexInterface; use Drupal\search_api\Item\Field; use Drupal\search_api\Plugin\search_api\data_type\value\TextToken; use Drupal\search_api\Plugin\search_api\data_type\value\TextValue; use Drupal\search_api\Plugin\search_api\processor\HtmlFilter; use Drupal\search_api\Query\Condition; use Drupal\search_api\Utility\Utility; Loading Loading @@ -33,7 +35,7 @@ class HtmlFilterTest extends UnitTestCase { } /** * Tests preprocessing field values with "title" settings. * Tests preprocessing field values with different "title" settings. * * @param string $passed_value * The value that should be passed into process(). Loading Loading @@ -75,7 +77,7 @@ class HtmlFilterTest extends UnitTestCase { } /** * Tests preprocessing field values with "alt" settings. * Tests preprocessing field values with different "alt" settings. * * @param string $passed_value * The value that should be passed into process(). Loading Loading @@ -151,7 +153,7 @@ class HtmlFilterTest extends UnitTestCase { } /** * Tests preprocessing field values with "alt" settings. * Tests preprocessing field values with different "tags" settings. * * @param string $passed_value * The value that should be passed into process(). Loading Loading @@ -305,4 +307,40 @@ class HtmlFilterTest extends UnitTestCase { $this->assertSame([$condition], $conditions); } /** * Tests empty values handling. * * @see https://www.drupal.org/project/search_api/issues/3212925 */ public function testEmptyValueHandling() { $index = $this->createMock(IndexInterface::class); $field = (new Field($index, 'field')) ->setType('text'); $index->method('getFields')->willReturn([ 'field' => $field, ]); $field->setValues([new TextValue('<p></p>')]); $this->invokeMethod('processField', [$field]); $this->assertEquals([], $field->getValues()); $value = new TextValue('<p></p>'); $value->setTokens([new TextToken('<p></p>')]); $field->setValues([$value]); $this->invokeMethod('processField', [$field]); $this->assertEquals([], $field->getValues()); // In theory, setting the value of a "text" field to a string instead of a // TextValue object is not allowed, but when it happens we might as well // handle it graciously (though other parts of the framework might not). $field->setValues(['<p></p>']); $this->invokeMethod('processField', [$field]); $this->assertEquals([], $field->getValues()); $field->setType('string'); $field->setValues(['<p></p>']); $this->invokeMethod('processField', [$field]); $this->assertEquals([], $field->getValues()); } }