Skip to content

Commit

Permalink
CB-12250 CB-12409 iOS: Fix bug with escaping properties from plist file
Browse files Browse the repository at this point in the history
  • Loading branch information
matrosov-nikita committed Mar 29, 2017
1 parent 4c99c0d commit 2f5a4df
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
42 changes: 42 additions & 0 deletions cordova-common/spec/plist-helpers.spec.js
@@ -0,0 +1,42 @@
var plistHelpers = require('../src/util/plist-helpers');


describe('prunePLIST', function() {
var doc = {
FirstConfigKey: {
FirstPreferenceName: '*',
SecondPreferenceName: 'a + b',
ThirdPreferenceName: 'x-msauth-$(CFBundleIdentifier:rfc1034identifier)'
},

SecondConfigKey: {
FirstPreferenceName: 'abc'
}
};

var xml = '<dict>' +
'<key>FirstPreferenceName</key>' +
'<string>*</string>' +
'<key>SecondPreferenceName</key>' +
'<string>a + b</string>' +
'<key>ThirdPreferenceName</key>' +
'<string>x-msauth-$(CFBundleIdentifier:rfc1034identifier)</string>' +
'</dict>';

var selector = 'FirstConfigKey';

it('Test 01: should remove property from plist file using provided selector', function(done) {
var pruneStatus = plistHelpers.prunePLIST(doc, xml, selector);

expect(pruneStatus).toBeTruthy();
expect(doc).toEqual(
{
SecondConfigKey: {
FirstPreferenceName: 'abc'
}
}
);

done();
});
});
4 changes: 2 additions & 2 deletions cordova-common/src/util/plist-helpers.js
Expand Up @@ -84,7 +84,7 @@ function nodeEqual(node1, node2) {
if (typeof node1 != typeof node2)
return false;
else if (typeof node1 == 'string') {
node2 = escapeRE(node2).replace(new RegExp('\\$[a-zA-Z0-9-_]+','gm'),'(.*?)');
node2 = escapeRE(node2).replace(/\\\$\S+/gm,'(.*?)');
return new RegExp('^' + node2 + '$').test(node1);
}
else {
Expand All @@ -97,5 +97,5 @@ function nodeEqual(node1, node2) {

// escape string for use in regex
function escapeRE(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '$&');
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}
4 changes: 2 additions & 2 deletions cordova-lib/src/plugman/util/plist-helpers.js
Expand Up @@ -84,7 +84,7 @@ function nodeEqual(node1, node2) {
if (typeof node1 != typeof node2)
return false;
else if (typeof node1 == 'string') {
node2 = escapeRE(node2).replace(new RegExp('\\$[a-zA-Z0-9-_]+','gm'),'(.*?)');
node2 = escapeRE(node2).replace(/\\\$\S+/gm,'(.*?)');
return new RegExp('^' + node2 + '$').test(node1);
}
else {
Expand All @@ -97,5 +97,5 @@ function nodeEqual(node1, node2) {

// escape string for use in regex
function escapeRE(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '$&');
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}

0 comments on commit 2f5a4df

Please sign in to comment.