Page MenuHomePhabricator

ve.ui.MWWikitextStringTransferHandler uses bare content
Closed, ResolvedPublic


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 {
       doc, new ve.Range( 0, ), [], [], [ { 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

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

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