Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[file_selector_platform_interface]: Verify that extensions don't have leading dots. #3451

Merged
merged 8 commits into from
Feb 26, 2021
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

* Replace extensions with leading dots.

## 2.0.0

* Migration to null-safety
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class XTypeGroup {
/// allowed.
XTypeGroup({
this.label,
this.extensions,
List<String>? extensions,
this.mimeTypes,
this.macUTIs,
this.webWildCards,
});
}) : this.extensions = _removeLeadingDots(extensions);

/// The 'name' or reference to this group of types
final String? label;
Expand All @@ -41,4 +41,7 @@ class XTypeGroup {
'webWildCards': webWildCards,
};
}

static List<String>? _removeLeadingDots(List<String>? exts) =>
exts?.map((ext) => ext.startsWith('.') ? ext.substring(1) : ext).toList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the file_selector plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/file_selector/file_selector_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.0.0
version: 2.0.1

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ void main() {
test('passes the accepted type groups correctly', () async {
final group = XTypeGroup(
label: 'text',
extensions: ['.txt'],
extensions: ['txt'],
mimeTypes: ['text/plain'],
macUTIs: ['public.text'],
);

final groupTwo = XTypeGroup(
label: 'image',
extensions: ['.jpg'],
extensions: ['jpg'],
mimeTypes: ['image/jpg'],
macUTIs: ['public.image'],
webWildCards: ['image/*']);
Expand Down Expand Up @@ -90,14 +90,14 @@ void main() {
test('passes the accepted type groups correctly', () async {
final group = XTypeGroup(
label: 'text',
extensions: ['.txt'],
extensions: ['txt'],
mimeTypes: ['text/plain'],
macUTIs: ['public.text'],
);

final groupTwo = XTypeGroup(
label: 'image',
extensions: ['.jpg'],
extensions: ['jpg'],
mimeTypes: ['image/jpg'],
macUTIs: ['public.image'],
webWildCards: ['image/*']);
Expand Down Expand Up @@ -152,14 +152,14 @@ void main() {
test('passes the accepted type groups correctly', () async {
final group = XTypeGroup(
label: 'text',
extensions: ['.txt'],
extensions: ['txt'],
mimeTypes: ['text/plain'],
macUTIs: ['public.text'],
);

final groupTwo = XTypeGroup(
label: 'image',
extensions: ['.jpg'],
extensions: ['jpg'],
mimeTypes: ['image/jpg'],
macUTIs: ['public.image'],
webWildCards: ['image/*']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() {
group('XTypeGroup', () {
test('toJSON() creates correct map', () {
final label = 'test group';
final extensions = ['.txt', '.jpg'];
final extensions = ['txt', 'jpg'];
final mimeTypes = ['text/plain'];
final macUTIs = ['public.plain-text'];
final webWildCards = ['image/*'];
Expand Down Expand Up @@ -41,5 +41,12 @@ void main() {
expect(jsonMap['macUTIs'], null);
expect(jsonMap['webWildCards'], null);
});

test('Leading dots are removed from extensions', () {
final extensions = ['.txt', '.jpg'];
final group = XTypeGroup(extensions: extensions);

expect(group.extensions, ['txt', 'jpg']);
});
});
}