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

Commit 2082921

Browse files
committed
Remove leading dots without mutations.
1 parent 3a32e2f commit 2082921

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2020 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
import 'package:flutter/foundation.dart';
54

65
/// A set of allowed XTypes
76
class XTypeGroup {
@@ -11,27 +10,11 @@ class XTypeGroup {
1110
/// allowed.
1211
XTypeGroup({
1312
this.label,
14-
this.extensions,
13+
List<String>? extensions,
1514
this.mimeTypes,
1615
this.macUTIs,
1716
this.webWildCards,
18-
}) {
19-
_verifyExtensions();
20-
}
21-
22-
void _verifyExtensions() {
23-
if (extensions == null) return;
24-
final exts = extensions!;
25-
for (var i = 0; i < exts.length; i++) {
26-
if (!exts[i].startsWith('.')) continue;
27-
if (kDebugMode) {
28-
print('extensions[${i}] with value "${exts[i]}" is invalid.'
29-
' The leading dots are being removed from the extensions'
30-
' Please fix it.');
31-
}
32-
exts[i] = exts[i].substring(1);
33-
}
34-
}
17+
}) : this.extensions = _removeLeadingDots(extensions);
3518

3619
/// The 'name' or reference to this group of types
3720
final String? label;
@@ -58,4 +41,7 @@ class XTypeGroup {
5841
'webWildCards': webWildCards,
5942
};
6043
}
44+
45+
static List<String>? _removeLeadingDots(List<String>? exts) =>
46+
exts?.map((ext) => ext.startsWith('.') ? ext.substring(1) : ext).toList();
6147
}

packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ void main() {
4242
expect(jsonMap['webWildCards'], null);
4343
});
4444

45-
test('Validates extensions have not leading dots', () {
45+
test('Leading dots are removed from extensions', () {
4646
final extensions = ['.txt', '.jpg'];
4747
final group = XTypeGroup(extensions: extensions);
4848

49-
expect(group.extensions, extensions);
5049
expect(group.extensions, ['txt', 'jpg']);
5150
});
5251
});

0 commit comments

Comments
 (0)