Skip to content

Commit af93b6a

Browse files
authored
[flutter_tool] Improve yaml font map validation (flutter#42538)
1 parent 1ada412 commit af93b6a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/flutter_tools/lib/src/flutter_manifest.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,13 @@ void _validateFonts(YamlList fonts, List<String> errors) {
439439
errors.add('Expected "fonts" to either be null or a list.');
440440
continue;
441441
}
442-
for (final YamlMap fontListItem in fontMap['fonts']) {
443-
for (final MapEntry<dynamic, dynamic> kvp in fontListItem.entries) {
442+
for (final dynamic fontListItem in fontMap['fonts']) {
443+
if (fontListItem is! YamlMap) {
444+
errors.add('Expected "fonts" to be a list of maps.');
445+
continue;
446+
}
447+
final YamlMap fontMapList = fontListItem;
448+
for (final MapEntry<dynamic, dynamic> kvp in fontMapList.entries) {
444449
if (kvp.key is! String) {
445450
errors.add('Expected "${kvp.key}" under "fonts" to be a string.');
446451
}

packages/flutter_tools/test/general.shard/flutter_manifest_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,25 @@ flutter:
534534
expect(logger.errorText, contains('Expected "fonts" to either be null or a list.'));
535535
});
536536

537+
testUsingContext('Returns proper error when font detail is not a list of maps', () async {
538+
final BufferLogger logger = context.get<Logger>();
539+
const String manifest = '''
540+
name: test
541+
dependencies:
542+
flutter:
543+
sdk: flutter
544+
flutter:
545+
fonts:
546+
- family: foo
547+
fonts:
548+
- asset
549+
''';
550+
final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
551+
552+
expect(flutterManifest, null);
553+
expect(logger.errorText, contains('Expected "fonts" to be a list of maps.'));
554+
});
555+
537556
testUsingContext('Returns proper error when font is a map instead of a list', () async {
538557
final BufferLogger logger = context.get<Logger>();
539558
const String manifest = '''

0 commit comments

Comments
 (0)