Page MenuHomePhabricator

ve.ui.MWWikitextStringTransferHandler uses bare content
Closed, ResolvedPublic

Description

In ve.ui.MWWikitextStringTransferHandler#process we create, and return, invalid documents containing bare content not wrapped in a content branch node:

// Attempt to undo outermost p-wrapping if possible
try {
        surface.change(
                ve.dm.TransactionBuilder.static.newFromWrap( doc, new ve.Range( 0, doc.data.countNonInternalElements() ), [], [], [ { type: 'paragraph' } ], [] )
        );
} catch ( e ) {
        // Sometimes there is no p-wrapping, for example: "* foo"
        // Sometimes there are multiple <p> tags in the output.
        // That's okay: ignore the error and paste what we've got.
}
handler.resolve( doc );

This breaks VisualEditor's "no mixed content" paradigm. That can cause problems in a number of places. An immediate problem is that it's incompatible with TreeModifier, but fundamentally there are many reasons we shouldn't create documents like this.

Steps to reproduce:

  1. Open a blank mediawiki page in VisualEditor
  2. Open the inspector, and in ve.ui.MWWikitextStringTransferHandler put a breakpoint at handler.resolve( doc ) above
  3. From somewhere else, copy this plaintext: foo [[bar]] baz
  4. Paste it into VisualEditor
  5. Look at doc.data.data

Observed behaviour: The document data is ill-formed; it starts [ 'f', 'o', 'o', ... ] with no enclosing paragraph

Expected behaviour: The document data is well-formed; content only occurs inside ContentBranchNodes

Event Timeline

Change 537331 had a related patch set uploaded (by Divec; owner: Divec):
[mediawiki/extensions/VisualEditor@master] Don't unwrap a solitary paragraph in Wikitext string transfers

https://gerrit.wikimedia.org/r/537331

Change 537331 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] Don't unwrap a solitary paragraph in Wikitext string transfers

https://gerrit.wikimedia.org/r/537331