From 5fddb9be1c20d47adabb0d5e85fee2def0486ae8 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 24 Mar 2020 15:54:40 -0700 Subject: [PATCH] Add empty string check to Locale toString (#17280) --- lib/ui/window.dart | 4 ++-- testing/dart/locale_test.dart | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index c830b6f4c21..d52bfea1a6c 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -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(); } diff --git a/testing/dart/locale_test.dart b/testing/dart/locale_test.dart index 5f1f8378073..5bebd5106be 100644 --- a/testing/dart/locale_test.dart +++ b/testing/dart/locale_test.dart @@ -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'); + }); }