[wp-trac] [WordPress Trac] #28814: Early return undefined can cause exception in mce-views.js

WordPress Trac noreply at wordpress.org
Thu Jul 10 16:01:48 UTC 2014


#28814: Early return undefined can cause exception in mce-views.js
--------------------------+-----------------------------
 Reporter:  programmin    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  3.9.1
 Severity:  normal        |   Keywords:
  Focuses:  javascript    |
--------------------------+-----------------------------
 Part of mce-views.js is returning early (that is, returning undefined):


 {{{
 /**
                  * Set the data that will be used to compile the
 Underscore template,
                  *  compile the template, and then return it.
                  *
                  * @returns {string}
                  */
                 getHtml: function() {
                         var data = this.shortcode.attrs.named,
                                 model = wp.media.playlist,
                                 options,
                                 attachments,
                                 tracks = [];

                         // Don't render errors while still fetching
 attachments
                         if ( this.dfd && 'pending' === this.dfd.state() &&
 ! this.attachments.length ) {
                                 return;
                         }
 }}}

 Unfortunately that's breaking node.html( html ).append ''in some cases'',
 caused exception with a playlist of music files that no longer exist.

 {{{
 /**
                  * Get the HTML for the view (which also set's the data),
 replace the
                  *   current HTML, and then invoke the WPPlaylistView
 instance to render
                  *   the playlist in the editor
                  *
                  * @global WPPlaylistView
                  * @global tinymce.editors
                  */
                 render: function() {
                         var html = this.getHtml(), self = this;

                         _.each( tinymce.editors, function( editor ) {
                                 var doc;
                                 if ( editor.plugins.wpview ) {
                                         doc = editor.getDoc();
                                         $( doc ).find( '[data-wpview-
 text="' + this.encodedText + '"]' ).each(function (i, elem) {
                                                 var node = $( elem );

                                                 // The <ins> is used to
 mark the end of the wrapper div. Needed when comparing
                                                 // the content as string
 for preventing extra undo levels.
                                                 node.html( html ).append(
 '<ins data-wpview-end="1"></ins>' );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28814>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list