jenkins-bot has submitted this change and it was merged.

Change subject: Sanitize the paste context in the same way as the paste data
......................................................................


Sanitize the paste context in the same way as the paste data

Bug: T129310
Change-Id: Iaffb2ae769c8909b9c08c9f3351ecfe776be537e
---
M src/ce/ve.ce.Surface.js
M tests/ce/ve.ce.Surface.test.js
2 files changed, 32 insertions(+), 10 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index e60da7d..3f58de0 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1811,6 +1811,18 @@
                documentModel = surfaceModel.getDocument(),
                view = this;
 
+       function sanitize( linearData, keepEmptyContentBranches ) {
+               // If the clipboardKey isn't set (paste from non-VE instance) 
use external import rules
+               if ( !clipboardKey ) {
+                       linearData.sanitize( importRules.external || {}, 
keepEmptyContentBranches );
+                       if ( importRules.all ) {
+                               linearData.sanitize( importRules.all, 
keepEmptyContentBranches );
+                       }
+               } else {
+                       linearData.sanitize( importRules.all || {}, 
keepEmptyContentBranches );
+               }
+       }
+
        // If the selection doesn't collapse after paste then nothing was 
inserted
        if ( !this.nativeSelection.isCollapsed ) {
                return;
@@ -2034,15 +2046,7 @@
                data = pastedDocumentModel.data;
                // Clear metadata
                pastedDocumentModel.metadata = new ve.dm.MetaLinearData( 
pastedDocumentModel.getStore(), new Array( 1 + data.getLength() ) );
-               // If the clipboardKey isn't set (paste from non-VE instance) 
use external import rules
-               if ( !clipboardKey ) {
-                       data.sanitize( importRules.external || {} );
-                       if ( importRules.all ) {
-                               data.sanitize( importRules.all );
-                       }
-               } else {
-                       data.sanitize( importRules.all || {} );
-               }
+               sanitize( data );
                data.remapInternalListKeys( documentModel.getInternalList() );
 
                // Initialize node tree
@@ -2078,7 +2082,7 @@
                        );
                        if ( this.pasteSpecial ) {
                                // The context may have been sanitized, so 
sanitize here as well for comparison
-                               context.sanitize( importRules, true );
+                               sanitize( context, true );
                        }
 
                        // Remove matching context from the left
diff --git a/tests/ce/ve.ce.Surface.test.js b/tests/ce/ve.ce.Surface.test.js
index 12f0d0d..ad9eeb7 100644
--- a/tests/ce/ve.ce.Surface.test.js
+++ b/tests/ce/ve.ce.Surface.test.js
@@ -1102,6 +1102,24 @@
                                msg: 'Formatted text into paragraph with 
pasteSpecial'
                        },
                        {
+                               range: new ve.Range( 11 ),
+                               pasteHtml: '<i>Bar</i>',
+                               pasteSpecial: true,
+                               expectedRange: new ve.Range( 14 ),
+                               expectedOps: [
+                                       [
+                                               { type: 'retain', length: 11 },
+                                               {
+                                                       type: 'replace',
+                                                       insert: [ 'B', 'a', 'r' 
],
+                                                       remove: []
+                                               },
+                                               { type: 'retain', length: 
docLen - 11 }
+                                       ]
+                               ],
+                               msg: 'Formatted text into heading with 
pasteSpecial'
+                       },
+                       {
                                range: new ve.Range( 4 ),
                                pasteHtml: '<p>Bar</p>',
                                expectedRange: {

-- 
To view, visit https://gerrit.wikimedia.org/r/277232
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaffb2ae769c8909b9c08c9f3351ecfe776be537e
Gerrit-PatchSet: 2
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to