Make WordPress Core

Ticket #38409: 38409.2.diff

File 38409.2.diff, 6.0 KB (added by westonruter, 7 years ago)

https://github.com/xwp/wordpress-develop/commit/13e4b19ae58074b9bca4959a7892d0ec5c13a9ad

  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 3508bf5..05cd185 100644
     
    40554055                        // ssl certs.
    40564056
    40574057                        previewer.add( 'previewUrl', params.previewUrl ).setter( function( to ) {
    4058                                 var result, urlParser, newPreviewUrl, schemeMatchingPreviewUrl, queryParams;
     4058                                var result = null, urlParser, queryParams, parsedAllowedUrl, parsedCandidateUrls = [];
    40594059                                urlParser = document.createElement( 'a' );
    40604060                                urlParser.href = to;
    40614061
     
    40774077                                        }
    40784078                                }
    40794079
    4080                                 newPreviewUrl = urlParser.href;
    4081                                 urlParser.protocol = previewer.scheme.get() + ':';
    4082                                 schemeMatchingPreviewUrl = urlParser.href;
     4080                                parsedCandidateUrls.push( urlParser );
     4081
     4082                                // Prepend list with URL that matches the scheme/protocol of the iframe.
     4083                                if ( previewer.scheme.get() + ':' !== urlParser.protocol ) {
     4084                                        urlParser = document.createElement( 'a' );
     4085                                        urlParser.href = parsedCandidateUrls[0].href;
     4086                                        urlParser.protocol = previewer.scheme.get() + ':';
     4087                                        parsedCandidateUrls.unshift( urlParser );
     4088                                }
    40834089
    40844090                                // Attempt to match the URL to the control frame's scheme
    40854091                                // and check if it's allowed. If not, try the original URL.
    4086                                 $.each( [ schemeMatchingPreviewUrl, newPreviewUrl ], function( i, url ) {
    4087                                         $.each( previewer.allowedUrls, function( i, allowed ) {
    4088                                                 var path;
    4089 
    4090                                                 allowed = allowed.replace( /\/+$/, '' );
    4091                                                 path = url.replace( allowed, '' );
    4092 
    4093                                                 if ( 0 === url.indexOf( allowed ) && /^([/#?]|$)/.test( path ) ) {
    4094                                                         result = url;
    4095                                                         return false;
     4092                                parsedAllowedUrl = document.createElement( 'a' );
     4093                                _.find( parsedCandidateUrls, function( parsedCandidateUrl ) {
     4094                                        return ! _.isUndefined( _.find( previewer.allowedUrls, function( allowedUrl ) {
     4095                                                parsedAllowedUrl.href = allowedUrl;
     4096                                                if ( urlParser.protocol === parsedAllowedUrl.protocol && urlParser.host === parsedAllowedUrl.host && 0 === parsedAllowedUrl.pathname.indexOf( urlParser.pathname ) ) {
     4097                                                        result = parsedCandidateUrl.href;
     4098                                                        return true;
    40964099                                                }
    4097                                         });
    4098                                         if ( result ) {
    4099                                                 return false;
    4100                                         }
    4101                                 });
     4100                                        } ) );
     4101                                } );
    41024102
    4103                                 // If we found a matching result, return it. If not, bail.
    4104                                 return result ? result : null;
     4103                                return result;
    41054104                        });
    41064105
    41074106                        previewer.bind( 'ready', previewer.ready );
  • src/wp-includes/js/customize-base.js

    diff --git src/wp-includes/js/customize-base.js src/wp-includes/js/customize-base.js
    index 11b868c..a8fa41d 100644
    window.wp = window.wp || {}; 
    654654                        this.add( 'origin', this.url() ).link( this.url ).setter( function( to ) {
    655655                                var urlParser = document.createElement( 'a' );
    656656                                urlParser.href = to;
    657                                 return urlParser.protocol + '//' + urlParser.hostname;
     657                                // Port stripping needed by IE since it adds to host but not to event.origin.
     658                                return urlParser.protocol + '//' + urlParser.host.replace( /:80$/, '' );
    658659                        });
    659660
    660661                        // first add with no value
  • src/wp-includes/js/customize-preview.js

    diff --git src/wp-includes/js/customize-preview.js src/wp-includes/js/customize-preview.js
    index 52de00d..f1bd852 100644
     
    275275         * @param {HTMLAnchorElement|HTMLAreaElement} element Link element.
    276276         * @param {string} element.search Query string.
    277277         * @param {string} element.pathname Path.
    278          * @param {string} element.hostname Hostname.
     278         * @param {string} element.host Host.
    279279         * @param {object} [options]
    280280         * @param {object} [options.allowAdminAjax=false] Allow admin-ajax.php requests.
    281281         * @returns {boolean} Is appropriate for changeset link.
    282282         */
    283283        api.isLinkPreviewable = function isLinkPreviewable( element, options ) {
    284                 var hasMatchingHost, urlParser, args;
     284                var matchesAllowedUrl, parsedAllowedUrl, args;
    285285
    286286                args = _.extend( {}, { allowAdminAjax: false }, options || {} );
    287287
     
    294294                        return false;
    295295                }
    296296
    297                 urlParser = document.createElement( 'a' );
    298                 hasMatchingHost = ! _.isUndefined( _.find( api.settings.url.allowed, function( allowedUrl ) {
    299                         urlParser.href = allowedUrl;
    300                         if ( urlParser.hostname === element.hostname && urlParser.protocol === element.protocol ) {
    301                                 return true;
    302                         }
    303                         return false;
     297                parsedAllowedUrl = document.createElement( 'a' );
     298                matchesAllowedUrl = ! _.isUndefined( _.find( api.settings.url.allowed, function( allowedUrl ) {
     299                        parsedAllowedUrl.href = allowedUrl;
     300                        return parsedAllowedUrl.protocol === element.protocol && parsedAllowedUrl.host === element.host && 0 === element.pathname.indexOf( parsedAllowedUrl.pathname );
    304301                } ) );
    305                 if ( ! hasMatchingHost ) {
     302                if ( ! matchesAllowedUrl ) {
    306303                        return false;
    307304                }
    308305
     
    331328         * @access protected
    332329         *
    333330         * @param {HTMLAnchorElement|HTMLAreaElement} element Link element.
    334          * @param {object} element.search Query string.
     331         * @param {string} element.search Query string.
     332         * @param {string} element.host Host.
     333         * @param {string} element.protocol Protocol.
    335334         * @returns {void}
    336335         */
    337336        api.prepareLinkPreview = function prepareLinkPreview( element ) {
     
    348347                }
    349348
    350349                // Make sure links in preview use HTTPS if parent frame uses HTTPS.
    351                 if ( 'https' === api.preview.scheme.get() && 'http:' === element.protocol && -1 !== api.settings.url.allowedHosts.indexOf( element.hostname ) ) {
     350                if ( 'https' === api.preview.scheme.get() && 'http:' === element.protocol && -1 !== api.settings.url.allowedHosts.indexOf( element.host ) ) {
    352351                        element.protocol = 'https:';
    353352                }
    354353
     
    496495                urlParser.href = form.action;
    497496
    498497                // Make sure forms in preview use HTTPS if parent frame uses HTTPS.
    499                 if ( 'https' === api.preview.scheme.get() && 'http:' === urlParser.protocol && -1 !== api.settings.url.allowedHosts.indexOf( urlParser.hostname ) ) {
     498                if ( 'https' === api.preview.scheme.get() && 'http:' === urlParser.protocol && -1 !== api.settings.url.allowedHosts.indexOf( urlParser.host ) ) {
    500499                        urlParser.protocol = 'https:';
    501500                        form.action = urlParser.href;
    502501                }