Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f2db93df
Unverified
Commit
f2db93df
authored
Aug 01, 2023
by
Alex Li
Committed by
GitHub
Aug 01, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐛
Treat empty ARB content as empty map when decoding (#131242)
Fixes #128932.
parent
d250fa62
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
16 deletions
+57
-16
gen_l10n_types.dart
...s/flutter_tools/lib/src/localizations/gen_l10n_types.dart
+27
-16
generate_localizations_test.dart
.../commands.shard/hermetic/generate_localizations_test.dart
+30
-0
No files found.
packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart
View file @
f2db93df
...
...
@@ -566,13 +566,18 @@ class Message {
}
}
// Represents the contents of one ARB file.
//
/
Represents the contents of one ARB file.
class
AppResourceBundle
{
/// Assuming that the caller has verified that the file exists and is readable.
factory
AppResourceBundle
(
File
file
)
{
// Assuming that the caller has verified that the file exists and is readable.
Map
<
String
,
Object
?>
resources
;
final
Map
<
String
,
Object
?>
resources
;
try
{
resources
=
json
.
decode
(
file
.
readAsStringSync
())
as
Map
<
String
,
Object
?>;
final
String
content
=
file
.
readAsStringSync
().
trim
();
if
(
content
.
isEmpty
)
{
resources
=
<
String
,
Object
?>{};
}
else
{
resources
=
json
.
decode
(
content
)
as
Map
<
String
,
Object
?>;
}
}
on
FormatException
catch
(
e
)
{
throw
L10nException
(
'The arb file
${file.path}
has the following formatting issue:
\n
'
...
...
@@ -657,20 +662,26 @@ class AppResourceBundleCollection {
final
RegExp
filenameRE
=
RegExp
(
r'(\w+)\.arb$'
);
final
Map
<
LocaleInfo
,
AppResourceBundle
>
localeToBundle
=
<
LocaleInfo
,
AppResourceBundle
>{};
final
Map
<
String
,
List
<
LocaleInfo
>>
languageToLocales
=
<
String
,
List
<
LocaleInfo
>>{};
final
List
<
File
>
files
=
directory
.
listSync
().
whereType
<
File
>().
toList
()..
sort
(
sortFilesByPath
);
// We require the list of files to be sorted so that
// "languageToLocales[bundle.locale.languageCode]" is not null
// by the time we handle locales with country codes.
final
List
<
File
>
files
=
directory
.
listSync
()
.
whereType
<
File
>()
.
where
((
File
e
)
=>
filenameRE
.
hasMatch
(
e
.
path
))
.
toList
()
..
sort
(
sortFilesByPath
);
for
(
final
File
file
in
files
)
{
if
(
filenameRE
.
hasMatch
(
file
.
path
))
{
final
AppResourceBundle
bundle
=
AppResourceBundle
(
file
);
if
(
localeToBundle
[
bundle
.
locale
]
!=
null
)
{
throw
L10nException
(
"Multiple arb files with the same '
${bundle.locale}
' locale detected.
\n
"
'Ensure that there is exactly one arb file for each locale.'
);
}
localeToBundle
[
bundle
.
locale
]
=
bundle
;
languageToLocales
[
bundle
.
locale
.
languageCode
]
??=
<
LocaleInfo
>[];
languageToLocales
[
bundle
.
locale
.
languageCode
]!.
add
(
bundle
.
locale
);
final
AppResourceBundle
bundle
=
AppResourceBundle
(
file
);
if
(
localeToBundle
[
bundle
.
locale
]
!=
null
)
{
throw
L10nException
(
"Multiple arb files with the same '
${bundle.locale}
' locale detected.
\n
"
'Ensure that there is exactly one arb file for each locale.'
);
}
localeToBundle
[
bundle
.
locale
]
=
bundle
;
languageToLocales
[
bundle
.
locale
.
languageCode
]
??=
<
LocaleInfo
>[];
languageToLocales
[
bundle
.
locale
.
languageCode
]!.
add
(
bundle
.
locale
);
}
languageToLocales
.
forEach
((
String
language
,
List
<
LocaleInfo
>
listOfCorrespondingLocales
)
{
...
...
packages/flutter_tools/test/commands.shard/hermetic/generate_localizations_test.dart
View file @
f2db93df
...
...
@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
import
'package:flutter_tools/src/build_system/targets/localizations.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/generate_localizations.dart'
;
import
'package:flutter_tools/src/localizations/gen_l10n_types.dart'
;
import
'../../integration.shard/test_data/basic_project.dart'
;
import
'../../src/common.dart'
;
...
...
@@ -501,4 +502,33 @@ format: true
throwsToolExit
(
message:
'Unexpected positional argument "false".'
)
);
});
group
(
AppResourceBundle
,
()
{
testWithoutContext
(
"can be parsed without FormatException when it's content is empty"
,
()
{
final
File
arbFile
=
fileSystem
.
file
(
fileSystem
.
path
.
join
(
'lib'
,
'l10n'
,
'app_en.arb'
))
..
createSync
(
recursive:
true
);
expect
(
AppResourceBundle
(
arbFile
),
isA
<
AppResourceBundle
>());
});
testUsingContext
(
"would not fail the gen-l10n command when it's content is empty"
,
()
async
{
fileSystem
.
file
(
fileSystem
.
path
.
join
(
'lib'
,
'l10n'
,
'app_en.arb'
)).
createSync
(
recursive:
true
);
final
File
pubspecFile
=
fileSystem
.
file
(
'pubspec.yaml'
)..
createSync
();
pubspecFile
.
writeAsStringSync
(
BasicProjectWithFlutterGen
().
pubspec
);
final
GenerateLocalizationsCommand
command
=
GenerateLocalizationsCommand
(
fileSystem:
fileSystem
,
logger:
logger
,
artifacts:
artifacts
,
processManager:
processManager
,
);
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'gen-l10n'
]);
final
Directory
outputDirectory
=
fileSystem
.
directory
(
fileSystem
.
path
.
join
(
'.dart_tool'
,
'flutter_gen'
,
'gen_l10n'
));
expect
(
outputDirectory
.
existsSync
(),
true
);
expect
(
outputDirectory
.
childFile
(
'app_localizations_en.dart'
).
existsSync
(),
true
);
expect
(
outputDirectory
.
childFile
(
'app_localizations.dart'
).
existsSync
(),
true
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment