Skip to content

Commit e8a0934

Browse files
committed
Fixed handling trailing punctuation in queries.
1 parent d8345f3 commit e8a0934

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/S2/Rose/Entity/Query.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @copyright 2016-2025 Roman Parpalak
4-
* @license MIT
4+
* @license https://opensource.org/license/mit MIT
55
*/
66

77
namespace S2\Rose\Entity;
@@ -156,6 +156,18 @@ public function valueToArray()
156156
if ($v !== 'ё' && false !== strpos($v, 'ё')) {
157157
$v = str_replace('ё', 'е', $v);
158158
}
159+
160+
if ($v === '' || !preg_match('#[\\p{L}\\d]#u', $v)) {
161+
continue;
162+
}
163+
164+
$trimmed = rtrim($v, StringHelper::WORD_COMPONENT_DELIMITERS);
165+
if ($trimmed === '') {
166+
unset($words[$k]);
167+
continue;
168+
}
169+
170+
$v = $trimmed;
159171
}
160172
unset($v);
161173

tests/unit/Rose/Entity/QueryTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* @copyright 2016-2024 Roman Parpalak
4-
* @license MIT
3+
* @copyright 2016-2025 Roman Parpalak
4+
* @license https://opensource.org/license/mit MIT
55
*/
66

77
namespace S2\Rose\Test\Entity;
@@ -66,6 +66,10 @@ public function testFilterInput(): void
6666
// Tests for compatibility of multiple rules
6767
$this->assertEquals(['a—b', '"', 'text'], (new Query('a–b «text»'))->valueToArray());
6868
$this->assertEquals(['a', ',', 'b'], (new Query(" a, \n b "))->valueToArray());
69+
$this->assertEquals(
70+
['похоже', ',', 'лучшие', 'времена', 'наступили', 'я', 'решил', 'доработать', 'и', 'опубликовать', 'движок'],
71+
(new Query('Похоже, лучшие времена наступили. Я решил доработать и опубликовать движок.'))->valueToArray()
72+
);
6973

7074
// Invalid inputs
7175
$this->assertSame([], (new Query(null))->valueToArray());

0 commit comments

Comments
 (0)