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

Details

Related Gerrit Patches:
mediawiki/extensions/VisualEditor : masterDon't unwrap a solitary paragraph in Wikitext string transfers

Event Timeline

dchan created this task.Sep 15 2019, 4:54 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 15 2019, 4:54 AM
Waymon32 closed this task as Resolved.Sep 15 2019, 9:39 AM
Restricted Application added a project: User-Ryasmeen. · View Herald TranscriptSep 15 2019, 9:39 AM
marcella reopened this task as Open.Sep 15 2019, 6:52 PM
dchan updated the task description. (Show Details)Sep 16 2019, 2:23 AM

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

ppelberg closed this task as Resolved.Oct 23 2019, 1:08 AM