Unverified Commit 94da7248 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] fix RangeError in gen-l10n by checking for empty string (#107604)

parent d7285394
......@@ -1050,6 +1050,9 @@ class LocalizationsGenerator {
}
static bool _isValidGetterAndMethodName(String name) {
if (name.isEmpty) {
return false;
}
// Public Dart method name must not start with an underscore
if (name[0] == '_') {
return false;
......
......@@ -124,6 +124,9 @@ class L10nException implements Exception {
L10nException(this.message);
final String message;
@override
String toString() => message;
}
// One optional named parameter to be used by a NumberFormat.
......
......@@ -992,9 +992,7 @@ class AppLocalizationsEn extends AppLocalizations {
});
testWithoutContext(
'throws an error attempting to add preferred locales '
'when there is no corresponding arb file for that '
'locale',
'throws an error attempting to add preferred locales when there is no corresponding arb file for that locale',
() {
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
......@@ -1161,6 +1159,38 @@ class AppLocalizationsEn extends AppLocalizations {
)),
);
});
testWithoutContext('throws when an empty string is used as a key', () {
const String arbFileStringWithEmptyResourceId = '''
{
"market": "MARKET",
"": {
"description": "This key is invalid"
}
}''';
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile('app_en.arb')
.writeAsStringSync(arbFileStringWithEmptyResourceId);
expect(
() => LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: 'app_en.arb',
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
).loadResources(),
throwsA(isA<L10nException>().having(
(L10nException e) => e.message,
'message',
contains('Invalid ARB resource name ""'),
)),
);
});
testWithoutContext('throws when the same locale is detected more than once', () {
const String secondMessageArbFileString = '''
{
......
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