CB-11691: Fix for modifying binary plists
authorDarryl Pogue <darryl@dpogue.ca>
Sat, 12 May 2018 07:22:21 +0000 (00:22 -0700)
committerDarryl Pogue <dvpdiner2@gmail.com>
Fri, 18 May 2018 16:55:40 +0000 (09:55 -0700)
The bplist-parser module returns the plist dictionary object wrapped in
an array. When making modifications with `<edit-config>` or
`<config-file>`, it would add the changes as properties to the array but
then ignore them when writing out to the filesystem.

spec/ConfigChanges/ConfigChanges.spec.js
spec/fixtures/plugins/org.apache.bplist/plugin.xml [new file with mode: 0644]
spec/fixtures/projects/ios-config-xml/SampleApp/SampleApp-binary.plist [new file with mode: 0644]
src/ConfigChanges/ConfigFile.js

index 0e200ae..a0abe5c 100644 (file)
@@ -34,6 +34,7 @@ var editconfigplugin = path.join(__dirname, '../fixtures/plugins/org.test.editco
 var editconfigplugin_two = path.join(__dirname, '../fixtures/plugins/org.test.editconfigtest_two');
 var varplugin = path.join(__dirname, '../fixtures/plugins/com.adobe.vars');
 var plistplugin = path.join(__dirname, '../fixtures/plugins/org.apache.plist');
+var bplistplugin = path.join(__dirname, '../fixtures/plugins/org.apache.bplist');
 var android_two_project = path.join(__dirname, '../fixtures/projects/android_two/*');
 var android_two_no_perms_project = path.join(__dirname, '../fixtures/projects/android_two_no_perms', '*');
 var ios_config_xml = path.join(__dirname, '../fixtures/projects/ios-config-xml/*');
@@ -425,6 +426,19 @@ describe('config-changes module', function () {
                     expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'), 'utf-8')).not.toMatch(/(<string>schema-a<\/string>[^]*){2,}/);
                 });
             });
+            describe('of binary plist config files', function () {
+                it('should merge dictionaries and arrays, removing duplicates', function () {
+                    shell.cp('-rf', ios_config_xml, temp);
+                    shell.cp('-rf', bplistplugin, plugins_dir);
+                    var platformJson = PlatformJson.load(plugins_dir, 'ios');
+                    platformJson.addInstalledPluginToPrepareQueue('org.apache.bplist', {});
+                    configChanges.process(plugins_dir, temp, 'ios', platformJson, pluginInfoProvider);
+                    var edited_plist = fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-binary.plist'), 'utf-8');
+                    expect(edited_plist).toMatch(/<key>UINewsstandIcon<\/key>[\s\S]*<key>CFBundlePrimaryIcon<\/key>/);
+                    expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-binary.plist'), 'utf-8')).toMatch(/<string>schema-b<\/string>/);
+                    expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-binary.plist'), 'utf-8')).not.toMatch(/(<string>schema-a<\/string>[^]*){2,}/);
+                });
+            });
             it('Test 025 : should resolve wildcard config-file targets to the project, if applicable', function () {
                 shell.cp('-rf', ios_config_xml, temp);
                 shell.cp('-rf', cbplugin, plugins_dir);
diff --git a/spec/fixtures/plugins/org.apache.bplist/plugin.xml b/spec/fixtures/plugins/org.apache.bplist/plugin.xml
new file mode 100644 (file)
index 0000000..ea6f1f9
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+
+<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    id="org.apache.bplist"
+    version="3.0.0">
+
+    <name>Binary PList updates</name>
+
+    <!-- ios -->
+    <platform name="ios">
+        <config-file target="*-binary.plist" parent="CFBundleIcons">
+            <dict>
+                <key>UINewsstandIcon</key>
+                <dict>
+                    <key>CFBundleIconFiles</key>
+                    <array>
+                        <string>Newsstand-Cover-Icon.png</string>
+                        <string>Newsstand-Cover-Icon@2x.png</string>
+                    </array>
+                    <key>UINewsstandBindingType</key>
+                    <string>UINewsstandBindingTypeMagazine</string>
+                    <key>UINewsstandBindingEdge</key>
+                    <string>UINewsstandBindingEdgeLeft</string>
+                </dict>
+            </dict>
+        </config-file>
+
+        <config-file target="*-binary.plist" parent="CFValidSchemas">
+            <array>
+                <string>schema-a</string>
+                <string>schema-b</string>
+            </array>
+        </config-file>
+    </platform>
+</plugin>
diff --git a/spec/fixtures/projects/ios-config-xml/SampleApp/SampleApp-binary.plist b/spec/fixtures/projects/ios-config-xml/SampleApp/SampleApp-binary.plist
new file mode 100644 (file)
index 0000000..67a5811
Binary files /dev/null and b/spec/fixtures/projects/ios-config-xml/SampleApp/SampleApp-binary.plist differ
index eb6df45..2e5ed5f 100644 (file)
@@ -82,7 +82,7 @@ function ConfigFile_load () {
         //       Do we still need to support binary plist?
         //       If yes, use plist.parseStringSync() and read the file once.
         self.data = isBinaryPlist(filepath) ?
-            modules.bplist.parseBuffer(fs.readFileSync(filepath)) :
+            modules.bplist.parseBuffer(fs.readFileSync(filepath))[0] :
             modules.plist.parse(fs.readFileSync(filepath, 'utf8'));
     }
 }