You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by dp...@apache.org on 2018/05/18 16:55:42 UTC
[cordova-common] branch master updated: CB-11691: Fix for modifying
binary plists
This is an automated email from the ASF dual-hosted git repository.
dpogue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-common.git
The following commit(s) were added to refs/heads/master by this push:
new 9b49374 CB-11691: Fix for modifying binary plists
9b49374 is described below
commit 9b4937493a397246188fee8284f62b9507a14c75
Author: Darryl Pogue <da...@dpogue.ca>
AuthorDate: Sat May 12 00:22:21 2018 -0700
CB-11691: Fix for modifying binary plists
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 | 14 ++++++
spec/fixtures/plugins/org.apache.bplist/plugin.xml | 54 +++++++++++++++++++++
.../SampleApp/SampleApp-binary.plist | Bin 0 -> 936 bytes
src/ConfigChanges/ConfigFile.js | 2 +-
4 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/spec/ConfigChanges/ConfigChanges.spec.js b/spec/ConfigChanges/ConfigChanges.spec.js
index 0e200ae..a0abe5c 100644
--- a/spec/ConfigChanges/ConfigChanges.spec.js
+++ b/spec/ConfigChanges/ConfigChanges.spec.js
@@ -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
index 0000000..ea6f1f9
--- /dev/null
+++ b/spec/fixtures/plugins/org.apache.bplist/plugin.xml
@@ -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
index 0000000..67a5811
Binary files /dev/null and b/spec/fixtures/projects/ios-config-xml/SampleApp/SampleApp-binary.plist differ
diff --git a/src/ConfigChanges/ConfigFile.js b/src/ConfigChanges/ConfigFile.js
index eb6df45..2e5ed5f 100644
--- a/src/ConfigChanges/ConfigFile.js
+++ b/src/ConfigChanges/ConfigFile.js
@@ -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'));
}
}
--
To stop receiving notification emails like this one, please contact
dpogue@apache.org.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org