Add type validation to non-template .arb file parsing logic (#139035)
Resolves https://github.com/flutter/flutter/issues/138297. When reading from a .arb file (which contains localizations of strings in the form of a user-defined JSON string-string map), validate the type of values that we read. See [this comment of mine on #138297](https://github.com/flutter/flutter/issues/138297#issuecomment-1827043260) to see how I arrived at this fix.
This commit is contained in:
@@ -1241,6 +1241,34 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
)),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('AppResourceBundle throws if file contains non-string value', () {
|
||||
const String inputPathString = 'lib/l10n';
|
||||
const String templateArbFileName = 'app_en.arb';
|
||||
const String outputFileString = 'app_localizations.dart';
|
||||
const String classNameString = 'AppLocalizations';
|
||||
|
||||
fs.file(fs.path.join(inputPathString, templateArbFileName))
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{ "helloWorld": "Hello World!" }');
|
||||
fs.file(fs.path.join(inputPathString, 'app_es.arb'))
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{ "helloWorld": {} }');
|
||||
|
||||
final LocalizationsGenerator generator = LocalizationsGenerator(
|
||||
fileSystem: fs,
|
||||
inputPathString: inputPathString,
|
||||
templateArbFileName: templateArbFileName,
|
||||
outputFileString: outputFileString,
|
||||
classNameString: classNameString,
|
||||
logger: logger,
|
||||
);
|
||||
expect(
|
||||
() => generator.loadResources(),
|
||||
throwsToolExit(message: 'Localized message for key "helloWorld" in '
|
||||
'"lib/l10n/app_es.arb" is not a string.'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('writeOutputFiles', () {
|
||||
|
||||
Reference in New Issue
Block a user