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

#114 Add function getXMLStringLength #116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions lib/parse.js
Expand Up @@ -77,6 +77,18 @@ function parse (xml) {
return plist;
}

/**
* Return length a XML string.
*
* @param {String} xml - the XML String to decode
* @return {integer} length - the string length
* @api public
*/
function getXMLStringLength(xml) {
var doc = new DOMParser().parseFromString(xml);
return doc.documentElement.childNodes.length;
}

/**
* Convert an XML based plist document into a JSON representation.
*
Expand Down
144 changes: 144 additions & 0 deletions test/parse.js
Expand Up @@ -499,5 +499,149 @@ int main(int argc, char *argv[])
CFBundleAllowMixedLocalizations: true
});
});
});
it('should parse an example "Cordova.plist" file', function () {
var xml = multiline(function () {
/*
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
#
# 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.
#
-->
<plist version="1.0">
<dict>
<key>UIWebViewBounce</key>
<true/>
<key>TopActivityIndicator</key>
<string>gray</string>
<key>EnableLocation</key>
<false/>
<key>EnableViewportScale</key>
<false/>
<key>AutoHideSplashScreen</key>
<true/>
<key>ShowSplashScreenSpinner</key>
<true/>
<key>MediaPlaybackRequiresUserAction</key>
<false/>
<key>AllowInlineMediaPlayback</key>
<false/>
<key>OpenAllWhitelistURLsInWebView</key>
<false/>
<key>BackupWebStorage</key>
<true/>
<key>ExternalHosts</key>
<array>
<string>*</string>
</array>
<key>Plugins</key>
<dict>
<key>Device</key>
<string>CDVDevice</string>
<key>Logger</key>
<string>CDVLogger</string>
<key>Compass</key>
<string>CDVLocation</string>
<key>Accelerometer</key>
<string>CDVAccelerometer</string>
<key>Camera</key>
<string>CDVCamera</string>
<key>NetworkStatus</key>
<string>CDVConnection</string>
<key>Contacts</key>
<string>CDVContacts</string>
<key>Debug Console</key>
<string>CDVDebugConsole</string>
<key>Echo</key>
<string>CDVEcho</string>
<key>File</key>
<string>CDVFile</string>
<key>FileTransfer</key>
<string>CDVFileTransfer</string>
<key>Geolocation</key>
<string>CDVLocation</string>
<key>Notification</key>
<string>CDVNotification</string>
<key>Media</key>
<string>CDVSound</string>
<key>Capture</key>
<string>CDVCapture</string>
<key>SplashScreen</key>
<string>CDVSplashScreen</string>
<key>Battery</key>
<string>CDVBattery</string>
</dict>
</dict>
</plist>
*/
});
var parsed = parse(xml);
assert.deepEqual(parsed, {
UIWebViewBounce: true,
TopActivityIndicator: 'gray',
EnableLocation: false,
EnableViewportScale: false,
AutoHideSplashScreen: true,
ShowSplashScreenSpinner: true,
MediaPlaybackRequiresUserAction: false,
AllowInlineMediaPlayback: false,
OpenAllWhitelistURLsInWebView: false,
BackupWebStorage: true,
ExternalHosts: [ '*' ],
Plugins: {
Device: 'CDVDevice',
Logger: 'CDVLogger',
Compass: 'CDVLocation',
Accelerometer: 'CDVAccelerometer',
Camera: 'CDVCamera',
NetworkStatus: 'CDVConnection',
Contacts: 'CDVContacts',
'Debug Console': 'CDVDebugConsole',
Echo: 'CDVEcho',
File: 'CDVFile',
FileTransfer: 'CDVFileTransfer',
Geolocation: 'CDVLocation',
Notification: 'CDVNotification',
Media: 'CDVSound',
Capture: 'CDVCapture',
SplashScreen: 'CDVSplashScreen',
Battery: 'CDVBattery'
}
});
});

it('Add function getXMLStringLength. Issue #114', function () {
var xml = multiline(function () {
var xmlPollution =
/*
<plist version="1.0">
<dict>
<key>__proto__</key>
<dict>
<key>length</key>
<string>polluted</string>
</dict>
</dict>
</plist>
*/
assert.equal(getXMLStringLength(xml), 8);
});
});
});