Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/85213
Change subject: Clipboard hash should ignore all node attributes ...................................................................... Clipboard hash should ignore all node attributes Some browsers normalise attributes (e.g. Firefox makes URLs absolute) so we have to remove them from the clipboard hash to make the comparable. Bug: 54377 Change-Id: Iadc4d886a5345b28370cbfa31eb665661e577eeb --- M modules/ve/ce/ve.ce.Surface.js 1 file changed, 14 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/13/85213/1 diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index 5eadc52..7ccc45d 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -154,11 +154,17 @@ * When pasting, browsers normalize HTML to varying degrees. * This hash creates a comparable string for validating clipboard contents. * - * @param {string} html Clipboard HTML + * @param {jQuery} $elements Clipboard HTML elements * @returns {string} Hash */ -ve.ce.Surface.static.getClipboardHash = function ( html ) { - return html.replace( /\s+/gm, '' ); +ve.ce.Surface.static.getClipboardHash = function ( $elements ) { + var hash = ''; + // Node attributes may be normalised (e.g. URLs made absolute) so just store nodeName + $elements.each( function () { + hash += this.textContent || this.nodeName; + } ); + // Whitespace may be added/removed, so strip it all + return hash.replace( /\s/gm, '' ); }; @@ -683,7 +689,7 @@ this.$pasteTarget.prepend( $( '<span>' ).attr( 'data-ve-clipboard-key', this.clipboardId + '-' + clipboardIndex ) ); - clipboardItem.hash = this.constructor.static.getClipboardHash( this.$pasteTarget.html() ); + clipboardItem.hash = this.constructor.static.getClipboardHash( this.$pasteTarget.contents() ); // If direct clipboard editing is not allowed, we must use the pasteTarget to // select the data we want to go in the clipboard rangyRange = rangy.createRange( this.getElementDocument() ); @@ -791,12 +797,12 @@ clipboardId = parts[0]; clipboardIndex = parts[1]; if ( clipboardId === this.clipboardId && this.clipboard[clipboardIndex] ) { - // Hash validation: either the hash must be null (i.e. text/xcustom was used) - // or it must be equal to the hash of the pasted HTML to assert that the HTML + // Hash validation: either text/xcustom was used or the hash must be + // equal to the hash of the pasted HTML to assert that the HTML // hasn't been modified in another editor before being pasted back. - if ( this.clipboard[clipboardIndex].hash === null || + if ( beforePasteData.custom || this.clipboard[clipboardIndex].hash === - this.constructor.static.getClipboardHash( beforePasteData.html || this.$pasteTarget.html() ) + this.constructor.static.getClipboardHash( $elements ) ) { slice = this.clipboard[clipboardIndex].data; } -- To view, visit https://gerrit.wikimedia.org/r/85213 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iadc4d886a5345b28370cbfa31eb665661e577eeb Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits