mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Locale: empty string equates to null (#17356)
This commit is contained in:
parent
82c7ab09a4
commit
020d7c5c80
@ -475,12 +475,14 @@ class Locale {
|
||||
return true;
|
||||
return other is Locale
|
||||
&& other.languageCode == languageCode
|
||||
&& other.scriptCode == scriptCode
|
||||
&& other.countryCode == countryCode;
|
||||
&& other.scriptCode == scriptCode // scriptCode cannot be ''
|
||||
&& (other.countryCode == countryCode // Treat '' as equal to null.
|
||||
|| other.countryCode != null && other.countryCode.isEmpty && countryCode == null
|
||||
|| countryCode != null && countryCode.isEmpty && other.countryCode == null);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => hashValues(languageCode, scriptCode, countryCode);
|
||||
int get hashCode => hashValues(languageCode, scriptCode, countryCode == '' ? null : countryCode);
|
||||
|
||||
static Locale _cachedLocale;
|
||||
static String _cachedLocaleString;
|
||||
|
||||
@ -13,8 +13,6 @@ void main() {
|
||||
expect(const Locale('en').toLanguageTag(), 'en');
|
||||
expect(const Locale('en'), const Locale('en', $null));
|
||||
expect(const Locale('en').hashCode, const Locale('en', $null).hashCode);
|
||||
expect(const Locale('en'), isNot(const Locale('en', '')));
|
||||
expect(const Locale('en').hashCode, isNot(const Locale('en', '').hashCode));
|
||||
expect(const Locale('en', 'US').toLanguageTag(), 'en-US');
|
||||
expect(const Locale('en', 'US').toString(), 'en_US');
|
||||
expect(const Locale('iw').toLanguageTag(), 'he');
|
||||
@ -52,6 +50,16 @@ void main() {
|
||||
isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn')));
|
||||
expect(const Locale.fromSubtags(languageCode: 'en').hashCode,
|
||||
isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode));
|
||||
|
||||
expect(const Locale('en', ''), const Locale('en'));
|
||||
expect(const Locale('en'), const Locale('en', ''));
|
||||
expect(const Locale('en'), const Locale('en'));
|
||||
expect(const Locale('en', ''), const Locale('en', ''));
|
||||
|
||||
expect(const Locale('en', ''), isNot(const Locale('en', 'GB')));
|
||||
expect(const Locale('en'), isNot(const Locale('en', 'GB')));
|
||||
expect(const Locale('en', 'GB'), isNot(const Locale('en', '')));
|
||||
expect(const Locale('en', 'GB'), isNot(const Locale('en')));
|
||||
});
|
||||
|
||||
test('Locale toString does not include separator for \'\'', () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user