comigor/fuzzy

Search crashes when tokenize = true and the query ends with a space

Closed this issue · 0 comments

Title says it all :) Here's an example test code:

import 'package:test/test.dart';
import 'package:fuzzy/fuzzy.dart';

void main() {
  test('Search works when tokenize = true and query ends with space', () {
    final fuse = Fuzzy(['apple juice'], options: FuzzyOptions(tokenize: true));
    expect(() => fuse.search('apple'), returnsNormally);
    expect(() => fuse.search('apple j'), returnsNormally);
    expect(() => fuse.search('apple '), returnsNormally);
  });
}

The first two expects succeed, but the last one fails with:

Expected: return normally
  Actual: <Closure: () => List<Result<dynamic>>>
   Which: threw ArgumentError:<Invalid argument(s): -1>

Here's the full stack trace from the test (i.e., removing the expectation):

dart:core                                    int.<<
package:fuzzy/bitap/bitap_search.dart 62:18  bitapSearch
package:fuzzy/bitap/bitap.dart 63:12         Bitap.search
package:fuzzy/fuzzy.dart 175:51              Fuzzy._analyze
package:fuzzy/fuzzy.dart 93:9                Fuzzy._search
package:fuzzy/fuzzy.dart 50:9                Fuzzy.search
test\test.dart 9:10                          main.<fn>

Invalid argument(s): -1