WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#28814 closed defect (bug) (fixed)

Early return undefined can cause exception in mce-views.js

Reported by: programmin Owned by:
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.9
Component: TinyMCE Keywords:
Focuses: javascript Cc:

Description

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>' );

Change History (2)

#1 @iseulde
5 years ago

  • Component changed from Editor to TinyMCE
  • Version changed from 3.9.1 to 3.9

Related: #28761.

#2 @azaozz
5 years ago

  • Milestone changed from Awaiting Review to 4.0
  • Resolution set to fixed
  • Status changed from new to closed

This was fixed some time ago. getHtml always returns a string now.

Note: See TracTickets for help on using tickets.