Add empty string check to Locale toString (#17280)

This commit is contained in:
Gary Qian 2020-03-24 15:54:40 -07:00 committed by GitHub
parent af440db830
commit 5fddb9be1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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();
}

View File

@ -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');
});
}