Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Remove leading dots without mutations.
  • Loading branch information
tugorez committed Feb 26, 2021
commit 2082921b9aa769e21f7774484d3571da6cebccf9
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2020 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';

/// A set of allowed XTypes
class XTypeGroup {
Expand All @@ -11,27 +10,11 @@ class XTypeGroup {
/// allowed.
XTypeGroup({
this.label,
this.extensions,
List<String>? extensions,
this.mimeTypes,
this.macUTIs,
this.webWildCards,
}) {
_verifyExtensions();
}

void _verifyExtensions() {
if (extensions == null) return;
final exts = extensions!;
for (var i = 0; i < exts.length; i++) {
if (!exts[i].startsWith('.')) continue;
if (kDebugMode) {
print('extensions[${i}] with value "${exts[i]}" is invalid.'
' The leading dots are being removed from the extensions'
' Please fix it.');
}
exts[i] = exts[i].substring(1);
}
}
}) : this.extensions = _removeLeadingDots(extensions);

/// The 'name' or reference to this group of types
final String? label;
Expand All @@ -58,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 @@ -42,11 +42,10 @@ void main() {
expect(jsonMap['webWildCards'], null);
});

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

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