From bb35aefffbc287efc9823abd4b0e451b86c37378 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 11 Jun 2010 12:36:23 -0700 Subject: [PATCH] Fix for ticket #797 When load a file is uploaded using a dialog box and the jquery plugin ajaxForm, the ajaxForm plugin uses an hidden iFrame element to send the multi-part form and this is where the response goes. The ajaxForm plugin then retrieves the document body and parses the result as a json string. If the file uploads properly everything is fine, but if it fails Gallery3 return the input form with the the error fields highlighted as part of the json response. As this response is returned to a hidden iframe, the browser attempts to manipulate it and all hell breaks loose. We lose the trailing brace, we start getting escaping of form tags. When the ajaxForm plugin retrieves the iFrame body its no longer a valid json frame and the parsing fails and the user sees no indication that it failed. --- lib/gallery.dialog.js | 3 ++- modules/watermark/controllers/admin_watermarks.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 3587108c97..f280a5257a 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -114,7 +114,8 @@ }, success: function(data) { if (data.form) { - $("#g-dialog form").replaceWith(data.form); + var formData = unescape(data.form); + $("#g-dialog form").replaceWith(formData); $("#g-dialog form :submit").removeClass("ui-state-disabled") .attr("disabled", null); self._ajaxify_dialog(); diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php index d26919d5f4..18b463ca8e 100644 --- a/modules/watermark/controllers/admin_watermarks.php +++ b/modules/watermark/controllers/admin_watermarks.php @@ -124,7 +124,7 @@ public function add() { array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - print json_encode(array("result" => "error", "form" => (string) $form)); + print json_encode(array("result" => "error", "form" => rawurlencode((string) $form))); } }