Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Sep 14, 2024
2 parents 1351ec0 + 748f8b9 commit 58b7c53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/model/filters/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ class PathFilter extends CollectionFilter {
static const type = 'path';

// including trailing separator
final String path;
late final String path;

// without trailing separator
final String _rootAlbum;
late final String _rootAlbum;

late final EntryFilter _test;

@override
List<Object?> get props => [path, reversed];

PathFilter(this.path, {super.reversed = false}) : _rootAlbum = path.substring(0, path.length - 1) {
PathFilter(String path, {super.reversed = false}) {
this.path = path.endsWith(pContext.separator) ? path : '$path${pContext.separator}';
_rootAlbum = this.path.substring(0, this.path.length - 1);
_test = (entry) {
final dir = entry.directory;
if (dir == null) return false;
// avoid string building in most cases
return dir.startsWith(_rootAlbum) && '$dir${pContext.separator}'.startsWith(path);
return dir.startsWith(_rootAlbum) && '$dir${pContext.separator}'.startsWith(this.path);
};
}

Expand Down
13 changes: 9 additions & 4 deletions test/model/filters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ void main() {
final subImage = FakeMediaStoreService.newImage(subAlbum, 'image1');
final siblingImage = FakeMediaStoreService.newImage(siblingAlbum, 'image1');

final path = PathFilter('$rootAlbum/');
expect(path.test(rootImage), true);
expect(path.test(subImage), true);
expect(path.test(siblingImage), false);
final untrailedPath = PathFilter(rootAlbum);
expect(untrailedPath.test(rootImage), true);
expect(untrailedPath.test(subImage), true);
expect(untrailedPath.test(siblingImage), false);

final trailedPath = PathFilter('$rootAlbum/');
expect(trailedPath.test(rootImage), true);
expect(trailedPath.test(subImage), true);
expect(trailedPath.test(siblingImage), false);
});
}

0 comments on commit 58b7c53

Please sign in to comment.