Unverified Commit af93b6af authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Improve yaml font map validation (#42538)

parent 1ada412d
......@@ -439,8 +439,13 @@ void _validateFonts(YamlList fonts, List<String> errors) {
errors.add('Expected "fonts" to either be null or a list.');
continue;
}
for (final YamlMap fontListItem in fontMap['fonts']) {
for (final MapEntry<dynamic, dynamic> kvp in fontListItem.entries) {
for (final dynamic fontListItem in fontMap['fonts']) {
if (fontListItem is! YamlMap) {
errors.add('Expected "fonts" to be a list of maps.');
continue;
}
final YamlMap fontMapList = fontListItem;
for (final MapEntry<dynamic, dynamic> kvp in fontMapList.entries) {
if (kvp.key is! String) {
errors.add('Expected "${kvp.key}" under "fonts" to be a string.');
}
......
......@@ -534,6 +534,25 @@ flutter:
expect(logger.errorText, contains('Expected "fonts" to either be null or a list.'));
});
testUsingContext('Returns proper error when font detail is not a list of maps', () async {
final BufferLogger logger = context.get<Logger>();
const String manifest = '''
name: test
dependencies:
flutter:
sdk: flutter
flutter:
fonts:
- family: foo
fonts:
- asset
''';
final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
expect(flutterManifest, null);
expect(logger.errorText, contains('Expected "fonts" to be a list of maps.'));
});
testUsingContext('Returns proper error when font is a map instead of a list', () async {
final BufferLogger logger = context.get<Logger>();
const String manifest = '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment