From c8c935cd83ca0d86b9bd18843dd9db899f6719f7 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Wed, 30 Jan 2019 07:32:05 -0800 Subject: [PATCH] Allow bundle identifier to be surrounded with quotes. (#26300) Picked up from #22498, originally by @jugyo --- packages/flutter_tools/lib/src/project.dart | 4 ++-- packages/flutter_tools/test/project_test.dart | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart index 9e4bdacb15..bfbe689bd0 100644 --- a/packages/flutter_tools/lib/src/project.dart +++ b/packages/flutter_tools/lib/src/project.dart @@ -156,7 +156,7 @@ class IosProject { /// The parent of this project. final FlutterProject parent; - static final RegExp _productBundleIdPattern = RegExp(r'^\s*PRODUCT_BUNDLE_IDENTIFIER\s*=\s*(.*);\s*$'); + static final RegExp _productBundleIdPattern = RegExp(r'''^\s*PRODUCT_BUNDLE_IDENTIFIER\s*=\s*(["']?)(.*?)\1;\s*$'''); static const String _productBundleIdVariable = r'$(PRODUCT_BUNDLE_IDENTIFIER)'; static const String _hostAppBundleName = 'Runner'; @@ -225,7 +225,7 @@ class IosProject { // Info.plist has no build variables in product bundle ID. return fromPlist; } - final String fromPbxproj = _firstMatchInFile(xcodeProjectInfoFile, _productBundleIdPattern)?.group(1); + final String fromPbxproj = _firstMatchInFile(xcodeProjectInfoFile, _productBundleIdPattern)?.group(2); if (fromPbxproj != null && (fromPlist == null || fromPlist == _productBundleIdVariable)) { // Common case. Avoids parsing build settings. return fromPbxproj; diff --git a/packages/flutter_tools/test/project_test.dart b/packages/flutter_tools/test/project_test.dart index b36ba16472..82bbf89aaa 100644 --- a/packages/flutter_tools/test/project_test.dart +++ b/packages/flutter_tools/test/project_test.dart @@ -271,6 +271,21 @@ void main() { when(mockIOSWorkflow.getPlistValueFromFile(any, any)).thenReturn('\$(PRODUCT_BUNDLE_IDENTIFIER).\$(SUFFIX)'); expect(project.ios.productBundleIdentifier, 'io.flutter.someProject.suffix'); }); + testWithMocks('empty surrounded by quotes', () async { + final FlutterProject project = await someProject(); + addIosWithBundleId(project.directory, '', qualifier: '"'); + expect(project.ios.productBundleIdentifier, ''); + }); + testWithMocks('surrounded by double quotes', () async { + final FlutterProject project = await someProject(); + addIosWithBundleId(project.directory, 'io.flutter.someProject', qualifier: '"'); + expect(project.ios.productBundleIdentifier, 'io.flutter.someProject'); + }); + testWithMocks('surrounded by single quotes', () async { + final FlutterProject project = await someProject(); + addIosWithBundleId(project.directory, 'io.flutter.someProject', qualifier: '\''); + expect(project.ios.productBundleIdentifier, 'io.flutter.someProject'); + }); }); group('organization names set', () { @@ -425,13 +440,13 @@ void expectNotExists(FileSystemEntity entity) { expect(entity.existsSync(), isFalse); } -void addIosWithBundleId(Directory directory, String id) { +void addIosWithBundleId(Directory directory, String id, {String qualifier}) { directory .childDirectory('ios') .childDirectory('Runner.xcodeproj') .childFile('project.pbxproj') ..createSync(recursive: true) - ..writeAsStringSync(projectFileWithBundleId(id)); + ..writeAsStringSync(projectFileWithBundleId(id, qualifier: qualifier)); } void addAndroidWithApplicationId(Directory directory, String id) { @@ -460,13 +475,13 @@ flutter: invalid: '''; -String projectFileWithBundleId(String id) { +String projectFileWithBundleId(String id, {String qualifier}) { return ''' 97C147061CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { - PRODUCT_BUNDLE_IDENTIFIER = $id; + PRODUCT_BUNDLE_IDENTIFIER = ${qualifier ?? ''}$id${qualifier ?? ''}; PRODUCT_NAME = "\$(TARGET_NAME)"; }; name = Debug;