Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-13496: Fix greedy regex in plist-helpers #45

Merged
merged 1 commit into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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