mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tool] Improve yaml font map validation (#42538)
This commit is contained in:
parent
1ada412d1b
commit
af93b6af80
@ -439,8 +439,13 @@ void _validateFonts(YamlList fonts, List<String> errors) {
|
|||||||
errors.add('Expected "fonts" to either be null or a list.');
|
errors.add('Expected "fonts" to either be null or a list.');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (final YamlMap fontListItem in fontMap['fonts']) {
|
for (final dynamic fontListItem in fontMap['fonts']) {
|
||||||
for (final MapEntry<dynamic, dynamic> kvp in fontListItem.entries) {
|
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) {
|
if (kvp.key is! String) {
|
||||||
errors.add('Expected "${kvp.key}" under "fonts" to be a 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.'));
|
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 {
|
testUsingContext('Returns proper error when font is a map instead of a list', () async {
|
||||||
final BufferLogger logger = context.get<Logger>();
|
final BufferLogger logger = context.get<Logger>();
|
||||||
const String manifest = '''
|
const String manifest = '''
|
||||||
|
Loading…
Reference in New Issue
Block a user