From 66d6f884d97863d3498c31a900398318f1a856f6 Mon Sep 17 00:00:00 2001 From: sakaitaka Date: Wed, 2 Mar 2022 12:07:42 +0900 Subject: [PATCH] #114 Add function getXMLStringLength --- lib/parse.js | 12 +++++ test/parse.js | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/lib/parse.js b/lib/parse.js index 731161e..8b3e453 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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. * diff --git a/test/parse.js b/test/parse.js index 0dd10ba..2548079 100644 --- a/test/parse.js +++ b/test/parse.js @@ -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 () { +/* + + + + + + UIWebViewBounce + + TopActivityIndicator + gray + EnableLocation + + EnableViewportScale + + AutoHideSplashScreen + + ShowSplashScreenSpinner + + MediaPlaybackRequiresUserAction + + AllowInlineMediaPlayback + + OpenAllWhitelistURLsInWebView + + BackupWebStorage + + 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 + + + +*/ + }); + 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 = +/* + + + __proto__ + + length + polluted + + + +*/ + assert.equal(getXMLStringLength(xml), 8); + }); }); });