Skip to content

Commit

Permalink
CB-13496: Fix greedy regex in plist-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Sep 11, 2018
1 parent ce3801a commit 9c6cda3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions spec/plist-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,35 @@ describe('prunePLIST', function () {
done();
});
});

describe('plistGraft', function () {
let doc = {
'keychain-access-groups': [
'$(AppIdentifierPrefix)io.cordova.hellocordova',
'$(AppIdentifierPrefix)com.example.mylib'
]
};

let xml = '<array>' +
'<string>$(AppIdentifierPrefix)io.cordova.hellocordova</string>' +
'<string>$(AppIdentifierPrefix)com.example.mylib</string>' +
'</array>';

let selector = 'keychain-access-groups';

it('Test 01: should not mangle existing plist entries', function (done) {
var graftStatus = plistHelpers.graftPLIST(doc, xml, selector);

expect(graftStatus).toBeTruthy();
expect(doc).toEqual(
{
'keychain-access-groups': [
'$(AppIdentifierPrefix)io.cordova.hellocordova',
'$(AppIdentifierPrefix)com.example.mylib'
]
}
);

done();
});
});
2 changes: 1 addition & 1 deletion src/util/plist-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function pruneOBJECT (doc, selector, fragment) {

function nodeEqual (node1, node2) {
if (typeof node1 !== typeof node2) { return false; } else if (typeof node1 === 'string') {
node2 = escapeRE(node2).replace(/\\\$\S+/gm, '(.*?)');
node2 = escapeRE(node2).replace(/\\\$\(\S+\)/gm, '(.*?)');
return new RegExp('^' + node2 + '$').test(node1);
} else {
for (var key in node2) {
Expand Down

0 comments on commit 9c6cda3

Please sign in to comment.