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

Add support for signed Plist files #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/parse.js
Expand Up @@ -63,7 +63,8 @@ function invariant(test, message) {
*/

function parse (xml) {
var doc = new DOMParser().parseFromString(xml);
var extracted = extractPlist(xml);
var doc = new DOMParser().parseFromString(extracted);
invariant(
doc.documentElement.nodeName === 'plist',
'malformed document. First element should be <plist>'
Expand All @@ -77,6 +78,22 @@ function parse (xml) {
return plist;
}

/**
* Extract only the Plist string from a potentially signed string containing Plist-encoded data.
* @param {String} plist - the Plist String to extract from
* @returns {String} extracted Plist string
* @api private
*/

function extractPlist(plist) {
var plistStart = plist.indexOf("<plist"), plistEnd = plist.indexOf("</plist>");

// Fallback to provided data if we can't find start and end, or, if somehow end precedes start.
if (plistStart < 0 || plistEnd < 0 || plistStart > plistEnd) return plist;

return plist.substring(plistStart, plistEnd + 8);
}

/**
* Convert an XML based plist document into a JSON representation.
*
Expand Down