diff --git a/modules/ve-mw/init/ve.init.mw.Target.js b/modules/ve-mw/init/ve.init.mw.Target.js index 3455a98180..06ec8f78b9 100644 --- a/modules/ve-mw/init/ve.init.mw.Target.js +++ b/modules/ve-mw/init/ve.init.mw.Target.js @@ -309,6 +309,27 @@ ve.init.mw.Target.static.apiRequest = function ( data, settings ) { return $.ajax( settings ); }; +/** + * Take a target document with a possibly relative base URL, and modify it to be absolute. + * The base URL of the target document is resolved using the base URL of the source document. + * @param {HTMLDocument} targetDoc Document whose base URL should be resolved + * @param {HTMLDocument} sourceDoc Document whose base URL should be used for resolution + */ +ve.init.mw.Target.static.fixBase = function ( targetDoc, sourceDoc ) { + var $base; + if ( !targetDoc.baseURI ) { + $base = $( 'base', targetDoc ); + if ( $base.length ) { + // Modify the existing tag + $base.attr( 'href', ve.resolveUrl( $base.attr( 'href' ), sourceDoc ) ); + } else { + // No tag, add one + $base = $( '', targetDoc ).attr( 'href', sourceDoc.baseURI ); + $( 'head', sourceDoc ).append( $base ); + } + } +}; + /** * Handle the RL modules for VE and registered plugin modules being loaded. * @@ -367,6 +388,9 @@ ve.init.mw.Target.onLoad = function ( response ) { this.originalHtml = data.content; this.doc = ve.createDocumentFromHtml( this.originalHtml ); + // Parsoid outputs a protocol-relative tag, so absolutize it + this.constructor.static.fixBase( this.doc, document ); + this.remoteNotices = ve.getObjectValues( data.notices ); this.$checkboxes = $( ve.getObjectValues( data.checkboxes ).join( '' ) ); // Populate checkboxes with default values for minor and watch