Skip to content

Commit

Permalink
[file_selector_platform_interface]: Verify that extensions don't have…
Browse files Browse the repository at this point in the history
… leading dots. (flutter#3451)
  • Loading branch information
tugorez authored Feb 26, 2021
1 parent 4afca62 commit 4b4913c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
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']);
});
});
}

0 comments on commit 4b4913c

Please sign in to comment.