Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.1

- **Fix**: Make character set lookup faster in `containsAnyOf`.
- Used a Set of runes instead of checking characters linearly.
- Added unit tests for empty inputs, mismatches, and Unicode characters.

## 1.0.0

- Initial release of `password_engine`.
Expand Down
5 changes: 3 additions & 2 deletions lib/src/utils/password_string_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ extension PasswordStringX on String {
/// Uses a [Set] for O(1) lookup per character instead of O(m) string search.
bool containsAnyOf(String charSet) {
if (charSet.isEmpty) return false;
for (var i = 0; i < length; i++) {
if (charSet.contains(this[i])) return true;
final set = charSet.runes.toSet();
for (final rune in runes) {
if (set.contains(rune)) return true;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: password_engine
description: "A comprehensive and extensible password generation library for Dart and Flutter"
version: 1.0.0
version: 1.0.1
homepage: https://github.com/dhruvanbhalara/password_engine
repository: https://github.com/dhruvanbhalara/password_engine
issue_tracker: https://github.com/dhruvanbhalara/password_engine/issues
Expand Down
19 changes: 19 additions & 0 deletions test/utils/password_string_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,24 @@ void main() {
expect(''.hasUnicode, isFalse);
expect(('a' * 1000 + '\u03C0').hasUnicode, isTrue);
});

group('containsAnyOf', () {
test('returns false on empty charset pool', () {
expect('abc'.containsAnyOf(''), isFalse);
});

test('returns false when no characters match', () {
expect('abc'.containsAnyOf('xyz'), isFalse);
});

test('returns true when character matches', () {
expect('abc'.containsAnyOf('cxz'), isTrue);
});

test('handles unicode characters correctly', () {
expect('abc\u{1F60A}'.containsAnyOf('\u{1F60A}'), isTrue);
expect('abc\u{1F60A}'.containsAnyOf('\u{1F60B}'), isFalse);
});
});
});
}
Loading