← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:avoid-msg-edit-crash-on-deleted-messages into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:avoid-msg-edit-crash-on-deleted-messages into launchpad:master.

Commit message:
Avoiding msg edit JS crash when displaying a msg without content

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/403218
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:avoid-msg-edit-crash-on-deleted-messages into launchpad:master.
diff --git a/lib/lp/services/messages/javascript/messages.edit.js b/lib/lp/services/messages/javascript/messages.edit.js
index 3c4c0e5..a1e6806 100644
--- a/lib/lp/services/messages/javascript/messages.edit.js
+++ b/lib/lp/services/messages/javascript/messages.edit.js
@@ -181,6 +181,11 @@ YUI.add('lp.services.messages.edit', function(Y) {
             "cancel_btn": container.one('.editable-message-cancel-btn'),
             "last_edit": container.one('.editable-message-last-edit-date')
         };
+        // If the msg body or the msg form are not defined, don't try to do
+        // anything else.
+        if (!elements.msg_form || !elements.msg_body) {
+            return;
+        }
         elements.textarea = elements.msg_form.one('textarea');
 
         module.hideEditMessageField(elements.msg_body, elements.msg_form);
diff --git a/lib/lp/services/messages/javascript/tests/test_messages.edit.html b/lib/lp/services/messages/javascript/tests/test_messages.edit.html
index 94c60ea..1ef776f 100644
--- a/lib/lp/services/messages/javascript/tests/test_messages.edit.html
+++ b/lib/lp/services/messages/javascript/tests/test_messages.edit.html
@@ -91,5 +91,14 @@ GNU Affero General Public License version 3 (see the file LICENSE).
                 <input type="button" value="Cancel" class="editable-message-cancel-btn" />
             </div>
         </div>
+
+        <!-- A deleted message may not define all tags and break the
+        initialization. Let's add one of those here to make sure that Y.lp
+        .services.messages.edit.setup() will not crash. -->
+        <div class="editable-message" id="deleted-message"
+             data-baseurl="/message/2">
+            Deleted msg.
+        </div>
+
     </body>
 </html>

Follow ups