mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add empty string check to Locale toString (#17280)
This commit is contained in:
parent
af440db830
commit
5fddb9be1c
@ -508,9 +508,9 @@ class Locale {
|
||||
|
||||
String _rawToString(String separator) {
|
||||
final StringBuffer out = StringBuffer(languageCode);
|
||||
if (scriptCode != null)
|
||||
if (scriptCode != null && scriptCode.isNotEmpty)
|
||||
out.write('$separator$scriptCode');
|
||||
if (_countryCode != null)
|
||||
if (_countryCode != null && _countryCode.isNotEmpty)
|
||||
out.write('$separator$countryCode');
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
@ -53,4 +53,10 @@ void main() {
|
||||
expect(const Locale.fromSubtags(languageCode: 'en').hashCode,
|
||||
isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode));
|
||||
});
|
||||
|
||||
test('Locale toString does not include separator for \'\'', () {
|
||||
expect(const Locale('en').toString(), 'en');
|
||||
expect(const Locale('en', '').toString(), 'en');
|
||||
expect(const Locale('en', 'US').toString(), 'en_US');
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user