Fix #31764: Show appropriate error message when fonts pubspec.yaml isn't iterable
Show appropriate error message when fonts isn't iterable
This commit is contained in:
@@ -398,11 +398,11 @@ void _validateFonts(YamlList fonts, List<String> errors) {
|
||||
if (fontMap['family'] != null && fontMap['family'] is! String) {
|
||||
errors.add('Font family must either be null or a String.');
|
||||
}
|
||||
if (fontMap['fonts'] != null && fontMap['fonts'] is! YamlList) {
|
||||
errors.add('Expected "fonts" to either be null or a list.');
|
||||
}
|
||||
if (fontMap['fonts'] == null) {
|
||||
continue;
|
||||
} else if (fontMap['fonts'] is! YamlList) {
|
||||
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) {
|
||||
|
||||
@@ -6,7 +6,9 @@ import 'dart:async';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/context.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/flutter_manifest.dart';
|
||||
|
||||
@@ -463,6 +465,7 @@ flutter:
|
||||
expectedBuildNumber: null,
|
||||
);
|
||||
});
|
||||
|
||||
test('parses no version clause', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
@@ -478,6 +481,26 @@ flutter:
|
||||
expectedBuildNumber: null,
|
||||
);
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/31764
|
||||
testUsingContext('Returns proper error when font detail is malformed', () async {
|
||||
final BufferLogger logger = context.get<Logger>();
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
fonts:
|
||||
- family: foo
|
||||
fonts:
|
||||
-asset: a/bar
|
||||
''';
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, contains('Expected "fonts" to either be null or a list.'));
|
||||
});
|
||||
});
|
||||
|
||||
group('FlutterManifest with MemoryFileSystem', () {
|
||||
|
||||
Reference in New Issue
Block a user