Repository: cordova-plugin-dialogs
Updated Branches:
  refs/heads/master 9dd1cbc51 -> 85b6bdca5


CB-8947:(ios) Fix crash. Convert non-string messages to strings. Added tests.

 This closes #80


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/commit/85b6bdca
Tree: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/85b6bdca
Diff: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/85b6bdca

Branch: refs/heads/master
Commit: 85b6bdca512bd8eb5772c449685a21d609f260f0
Parents: 9dd1cbc
Author: Don Coleman <dcole...@chariotsolutions.com>
Authored: Thu Jul 28 14:55:01 2016 -0400
Committer: Julio César <jcesarmob...@gmail.com>
Committed: Sat Jul 30 12:58:31 2016 +0200

----------------------------------------------------------------------
 tests/tests.js      | 32 +++++++++++++++++++++++++++++++-
 www/notification.js | 10 ++++++----
 2 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/85b6bdca/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index a4cf382..f5836f1 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -153,7 +153,9 @@ exports.defineManualTests = function (contentEl, 
createActionButton) {
         '<p/> <div id="built_in_confirm"></div>' +
         'Expected result: Dialog will have title "index.html" and say "You 
selected confirm". Press Cancel or OK to close dialog. Nothing will get updated 
in status box.' +
         '<p/> <div id="built_in_prompt"></div>' +
-        'Expected result: Dialog will have title "index.html" and say "This is 
a prompt". "Default value" will be in text box. Press Cancel or OK to close 
dialog. Nothing will get updated in status box.';
+        'Expected result: Dialog will have title "index.html" and say "This is 
a prompt". "Default value" will be in text box. Press Cancel or OK to close 
dialog. Nothing will get updated in status box.' +
+        '<p/> <h3>CB-8947 Tests</h3><div id="cb8947"></div>' +
+        'Expected results: Dialogs will not crash iOS';
 
     contentEl.innerHTML = '<div id="info"></div>' +
         dialogs_tests;
@@ -200,4 +202,32 @@ exports.defineManualTests = function (contentEl, 
createActionButton) {
             prompt('This is a prompt', 'Default value');
         }
     }, 'built_in_prompt');
+
+    // CB-8947 - ensure number messages don't crash iOS
+    createActionButton('Alert Dialog with Number', function () {
+        var callback = function() { clearLog(); console.log("Test passed"); };
+        navigator.notification.alert(17, callback);
+    }, 'cb8947');
+
+    // CB-8947 - ensure object messages don't crash iOS
+    createActionButton('Alert Dialog with Object', function () {
+        var object = { number: 42, message: "Make sure an object doesn't crash 
iOS", issue: 'CB-8947'};
+        var callback = function() { clearLog(); console.log("Test passed"); };
+        navigator.notification.alert(object, callback);
+    }, 'cb8947');
+
+    // CB-8947 - ensure object messages don't crash iOS
+    createActionButton('Confirm Dialog with Object', function () {
+        var object = { number: 42, message: "Make sure an object doesn't crash 
iOS", issue: 'CB-8947'};
+        var callback = function() { clearLog(); console.log("Test passed"); };
+        navigator.notification.confirm(object, callback);
+    }, 'cb8947');
+
+    // CB-8947 - ensure object messages don't crash iOS
+    createActionButton('Prompt Dialog with Object', function () {
+        var object = { number: 42, message: "Make sure an object doesn't crash 
iOS", issue: 'CB-8947'};
+        var callback = function() { clearLog(); console.log("Test passed"); };
+        navigator.notification.prompt(object, callback);
+    }, 'cb8947');
+
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/85b6bdca/www/notification.js
----------------------------------------------------------------------
diff --git a/www/notification.js b/www/notification.js
index 2296668..4db8f0f 100644
--- a/www/notification.js
+++ b/www/notification.js
@@ -37,9 +37,10 @@ module.exports = {
      * @param {String} buttonLabel          Label of the close button 
(default: OK)
      */
     alert: function(message, completeCallback, title, buttonLabel) {
+        var _message = (typeof message === "string" ? message : 
JSON.stringify(message));
         var _title = (typeof title === "string" ? title : "Alert");
         var _buttonLabel = (buttonLabel || "OK");
-        exec(completeCallback, null, "Notification", "alert", [message, 
_title, _buttonLabel]);
+        exec(completeCallback, null, "Notification", "alert", [_message, 
_title, _buttonLabel]);
     },
 
     /**
@@ -52,6 +53,7 @@ module.exports = {
      * @param {Array} buttonLabels          Array of the labels of the buttons 
(default: ['OK', 'Cancel'])
      */
     confirm: function(message, resultCallback, title, buttonLabels) {
+        var _message = (typeof message === "string" ? message : 
JSON.stringify(message));
         var _title = (typeof title === "string" ? title : "Confirm");
         var _buttonLabels = (buttonLabels || ["OK", "Cancel"]);
 
@@ -62,7 +64,7 @@ module.exports = {
 
         _buttonLabels = convertButtonLabels(_buttonLabels);
 
-        exec(resultCallback, null, "Notification", "confirm", [message, 
_title, _buttonLabels]);
+        exec(resultCallback, null, "Notification", "confirm", [_message, 
_title, _buttonLabels]);
     },
 
     /**
@@ -78,7 +80,7 @@ module.exports = {
      * @param {String} defaultText          Textbox input value (default: 
empty string)
      */
     prompt: function(message, resultCallback, title, buttonLabels, 
defaultText) {
-        var _message = (typeof message === "string" ? message : "Prompt 
message");
+        var _message = (typeof message === "string" ? message : 
JSON.stringify(message));
         var _title = (typeof title === "string" ? title : "Prompt");
         var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
 
@@ -125,4 +127,4 @@ function convertButtonLabels(buttonLabels) {
     }
 
     return buttonLabels;
-}
\ No newline at end of file
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to