Skip to content

Commit e45aec9

Browse files
authoredFeb 17, 2020
Merge pull request #5 from jnthnklvn/fix-blank-spaces
Fix search crash tokenize with leading or trailing whitespace strings
2 parents f290627 + 0c94720 commit e45aec9

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# CHANGELOG
2+
## 0.2.2
3+
- Fix bug for search in a list with some string that has leading or trailing whitespace when tokenize option is true
4+
25
## 0.2.1
36
- Fix bug for search empty list
47

‎lib/fuzzy.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Fuzzy<T> {
8181
for (var i = 0, len = list.length; i < len; i += 1) {
8282
_analyze(
8383
key: '',
84-
value: list[i].toString(),
84+
value: list[i].toString().trim(),
8585
record: list[i],
8686
index: i,
8787
tokenSearchers: tokenSearchers,

‎pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: fuzzy
2-
version: 0.2.1
2+
version: 0.2.2
33

44
authors:
55
- Igor Borges <igor@borges.dev>

‎test/fuzzy_test.dart

+22
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,28 @@ void main() {
210210
});
211211
});
212212

213+
group(
214+
'Search with match all tokens in a list of strings with leading and trailing whitespace',
215+
() {
216+
Fuzzy fuse;
217+
setUp(() {
218+
final customList = [' Apple', 'Orange ', ' Banana '];
219+
fuse = setup(
220+
itemList: customList,
221+
overwriteOptions: FuzzyOptions(tokenize: true),
222+
);
223+
});
224+
225+
test('When searching for the term "Banana"', () {
226+
final result = fuse.search('Banana');
227+
228+
expect(result.length, 1, reason: 'we get a list of exactly 1 item');
229+
expect(result[0].item, equals(' Banana '),
230+
reason:
231+
'whose value is the same, disconsidering leading and trailing whitespace');
232+
});
233+
});
234+
213235
group('Search with match all tokens', () {
214236
Fuzzy fuse;
215237
setUp(() {

0 commit comments

Comments
 (0)