Unverified Commit 3e65bb06 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Fix #31764: Show appropriate error message when fonts pubspec.yaml isn't iterable

Show appropriate error message when fonts isn't iterable
parent a8504405
...@@ -398,11 +398,11 @@ void _validateFonts(YamlList fonts, List<String> errors) { ...@@ -398,11 +398,11 @@ void _validateFonts(YamlList fonts, List<String> errors) {
if (fontMap['family'] != null && fontMap['family'] is! String) { if (fontMap['family'] != null && fontMap['family'] is! String) {
errors.add('Font family must either be null or a 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) { if (fontMap['fonts'] == null) {
continue; 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 YamlMap fontListItem in fontMap['fonts']) {
for (final MapEntry<dynamic, dynamic> kvp in fontListItem.entries) { for (final MapEntry<dynamic, dynamic> kvp in fontListItem.entries) {
......
...@@ -6,7 +6,9 @@ import 'dart:async'; ...@@ -6,7 +6,9 @@ import 'dart:async';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.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/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/flutter_manifest.dart'; import 'package:flutter_tools/src/flutter_manifest.dart';
...@@ -463,6 +465,7 @@ flutter: ...@@ -463,6 +465,7 @@ flutter:
expectedBuildNumber: null, expectedBuildNumber: null,
); );
}); });
test('parses no version clause', () async { test('parses no version clause', () async {
const String manifest = ''' const String manifest = '''
name: test name: test
...@@ -478,6 +481,26 @@ flutter: ...@@ -478,6 +481,26 @@ flutter:
expectedBuildNumber: null, 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', () { group('FlutterManifest with MemoryFileSystem', () {
......
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