Ticket #40771: 40771-1.diff
| File 40771-1.diff, 4.5 KB (added by , 9 years ago) |
|---|
-
src/wp-admin/js/widgets/media-video-widget.js
98 98 */ 99 99 fetchEmbed: function fetchEmbed() { 100 100 var control = this, url; 101 url = control.model.get( 'url' ) ;101 url = control.model.get( 'url' ).trim(); 102 102 103 103 // If we already have a local cache of the embed response, return. 104 104 if ( control.oembedResponses[ url ] ) { … … 113 113 control.fetchEmbedDfd = jQuery.ajax({ 114 114 url: wp.media.view.settings.oEmbedProxyUrl, 115 115 data: { 116 url: control.model.get( 'url' ),116 url: url, 117 117 maxwidth: control.model.get( 'width' ), 118 118 maxheight: control.model.get( 'height' ), 119 119 _wpnonce: wp.media.view.settings.nonce.wpRestApi, … … 142 142 renderPreview: function renderPreview() { 143 143 var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl, poster, isHostedEmbed = false, parsedUrl, mime, error; 144 144 attachmentId = control.model.get( 'attachment_id' ); 145 attachmentUrl = control.model.get( 'url' ) ;145 attachmentUrl = control.model.get( 'url' ).trim(); 146 146 error = control.model.get( 'error' ); 147 147 148 148 if ( ! attachmentId && ! attachmentUrl ) { -
src/wp-admin/js/widgets/media-widgets.js
142 142 /** 143 143 * Fetch media. 144 144 * 145 * This is a TEMPORARY measure until the WP API supports an oEmbed proxy endpoint. See #40450.146 *147 * @see https://core.trac.wordpress.org/ticket/40450148 145 * @returns {void} 149 146 */ 150 147 fetch: function() { 151 var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser; // eslint-disable-line consistent-this 148 var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser, url; // eslint-disable-line consistent-this 149 url = embedLinkView.model.get( 'url' ).trim(); 152 150 153 151 if ( embedLinkView.dfd && 'pending' === embedLinkView.dfd.state() ) { 154 152 embedLinkView.dfd.abort(); … … 167 165 }; 168 166 169 167 urlParser = document.createElement( 'a' ); 170 urlParser.href = embedLinkView.model.get( 'url' );168 urlParser.href = url; 171 169 matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ ); 172 170 if ( matches ) { 173 171 fileExt = matches[1]; … … 184 182 embedLinkView.dfd = $.ajax({ 185 183 url: wp.media.view.settings.oEmbedProxyUrl, 186 184 data: { 187 url: embedLinkView.model.get( 'url' ),185 url: url, 188 186 maxwidth: embedLinkView.model.get( 'width' ), 189 187 maxheight: embedLinkView.model.get( 'height' ), 190 188 _wpnonce: wp.media.view.settings.nonce.wpRestApi, … … 779 777 mediaFramePropToModelPropMap[ fieldSchema.media_prop || modelProp ] = modelProp; 780 778 }); 781 779 780 // Trim whitespace from url since it causes problems with oembeds. 781 if ( mediaFrameProps.url ) { 782 mediaFrameProps.url = mediaFrameProps.url.trim(); 783 } 784 782 785 _.each( mediaFrameProps, function( value, mediaProp ) { 783 786 var propName = mediaFramePropToModelPropMap[ mediaProp ] || mediaProp; 784 787 if ( control.model.schema[ propName ] ) { -
tests/qunit/wp-admin/js/widgets/test-media-video-widget.js
28 28 equal( mappedProps.preload, 'meta', 'mapModelToMediaFrameProps should set preload' ); 29 29 30 30 // Test mapMediaToModelProps(). 31 mappedProps = videoWidgetControlInstance.mapMediaToModelProps( { loop: false, preload: 'meta', url: testVideoUrl , title: 'random movie file title' } );31 mappedProps = videoWidgetControlInstance.mapMediaToModelProps( { loop: false, preload: 'meta', url: testVideoUrl + ' ', title: 'random movie file title' } ); 32 32 equal( mappedProps.title, undefined, 'mapMediaToModelProps should ignore title inputs' ); 33 33 equal( mappedProps.loop, false, 'mapMediaToModelProps should set loop' ); 34 34 equal( mappedProps.preload, 'meta', 'mapMediaToModelProps should set preload' ); 35 equal( mappedProps.url, testVideoUrl, 'mapMediaToModelProps should trim whitespace from urls' ); 35 36 }); 36 37 37 38 test( 'video widget control renderPreview', function( assert ) {