mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-20 18:12:51 +00:00
4bc814f1a0
New changes: 7906a6b9e build: Updating npm dependencies 92e6a5338 TextStyleAnnotation: Don't register abstract base class 456ca9b2e Localisation updates from https://translatewiki.net. a68ba80d2 Get all annotations by ranges dc49d9592 Demos: Default to WMUI theme 222ac7d23 Add unit tests for ve.dm.BranchNode#getAnnotationRanges ba73b9e91 Return annotation ranges in lexicographic order 6e40aa524 Localisation updates from https://translatewiki.net. 1a4640a4a ve.ce.Surface: Remove unused $deactivatedSelection and $findResults 9455e0f0a ve.ce.Surface: Replace text/xcustom clipboard storage with a custom key ddd14aa9b [BREAKING CHANGE] Move paste handling code to ve.ce.ClipboardHandler 19f0e500b CollabProcessDialog: Replace mw.user.getName with platform method ecd607353 Implement pasteSourceDetectors bae9101b7 Localisation updates from https://translatewiki.net. Added files: - src/ce/ve.ce.ClipboardHandler.js - tests/ce/ve.ce.ClipboardHandler.test.js Local changes: * Implement new paste handler architecture * Use new clipboard key Bug: T360624 Bug: T376306 Bug: T78696 Change-Id: Iea10d32b6132ae364d486cc6b96895bb937ac944
91 lines
3.8 KiB
JavaScript
91 lines
3.8 KiB
JavaScript
/*!
|
|
* VisualEditor MediaWiki-specific ContentEditable Surface tests.
|
|
*
|
|
* @copyright See AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.ce.Surface (MW)', ve.test.utils.newMwEnvironment() );
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'beforePaste/afterPaste', ( assert ) => {
|
|
const cases = [
|
|
{
|
|
documentHtml: '<p></p>',
|
|
rangeOrSelection: new ve.Range( 1 ),
|
|
pasteHtml: '<span typeof="mw:Entity" id="mwAB">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span>',
|
|
fromVe: true,
|
|
expectedRangeOrSelection: new ve.Range( 5 ),
|
|
expectedHtml: '<p><span typeof="mw:Entity">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span></p>',
|
|
msg: 'RESTBase IDs stripped'
|
|
},
|
|
{
|
|
documentHtml: '<p></p>',
|
|
rangeOrSelection: new ve.Range( 1 ),
|
|
pasteHtml: '<span typeof="mw:Entity" id="mwAB">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span>',
|
|
clipboardHandlerHtml: '<span>-</span><span>-</span>',
|
|
fromVe: true,
|
|
expectedRangeOrSelection: new ve.Range( 5 ),
|
|
expectedHtml: '<p><span typeof="mw:Entity">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span></p>',
|
|
msg: 'RESTBase IDs still stripped if used when important attributes dropped'
|
|
},
|
|
{
|
|
documentHtml: '<p></p>',
|
|
rangeOrSelection: new ve.Range( 1 ),
|
|
pasteHtml: 'a<sup id="cite_ref-1" class="reference"><a href="./Article#cite_note-1">[1]</a></sup>b',
|
|
expectedRangeOrSelection: new ve.Range( 3 ),
|
|
expectedHtml: '<p>ab</p>',
|
|
msg: 'Read mode references stripped'
|
|
},
|
|
{
|
|
documentHtml: '<p></p>',
|
|
rangeOrSelection: new ve.Range( 1 ),
|
|
pasteHtml: 'a<sup typeof="mw:Extension/ref" data-mw="{}" class="mw-ref reference" about="#mwt1" id="cite_ref-foo-0" rel="dc:references"><a href="./Article#cite_note-foo-0"><span class="mw-reflink-text ve-pasteProtect">[1]</span></a></sup>b',
|
|
expectedRangeOrSelection: new ve.Range( 5 ),
|
|
expectedHtml: '<p>a<sup typeof="mw:Extension/ref" data-mw="{"name":"ref"}" class="mw-ref reference"><a><span class="mw-reflink-text"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></span></a></sup>b</p>',
|
|
msg: 'VE references not stripped'
|
|
},
|
|
{
|
|
documentHtml: '<p></p>',
|
|
rangeOrSelection: new ve.Range( 1 ),
|
|
pasteHtml: '<a href="https://example.net/">Lorem</a> <a href="not-a-protocol:Some%20text">ipsum</a> <a href="mailto:example@example.net">dolor</a> <a href="javascript:alert()">sit amet</a>',
|
|
expectedRangeOrSelection: new ve.Range( 27 ),
|
|
// hrefs with invalid protocols get removed by DOMPurify, and these links become spans in
|
|
// ve.dm.LinkAnnotation.static.toDataElement (usually the span is stripped later)
|
|
expectedHtml: '<p>Lorem <span>ipsum</span> dolor <span>sit amet</span></p>',
|
|
config: {
|
|
importRules: {
|
|
external: {
|
|
blacklist: {
|
|
'link/mwExternal': true
|
|
}
|
|
}
|
|
}
|
|
},
|
|
msg: 'External links stripped'
|
|
},
|
|
{
|
|
documentHtml: '<p></p>',
|
|
rangeOrSelection: new ve.Range( 1 ),
|
|
pasteHtml: '<a href="https://example.net/">Lorem</a> <a href="not-a-protocol:Some%20text">ipsum</a> <a href="mailto:example@example.net">dolor</a> <a href="javascript:alert()">sit amet</a>',
|
|
expectedRangeOrSelection: new ve.Range( 27 ),
|
|
// hrefs with invalid protocols get removed by DOMPurify, and these links become spans in
|
|
// ve.dm.LinkAnnotation.static.toDataElement (usually the span is stripped later)
|
|
expectedHtml: '<p><a href="https://example.net/" rel="mw:ExtLink">Lorem</a> <span>ipsum</span> <a href="mailto:example@example.net" rel="mw:ExtLink">dolor</a> <span>sit amet</span></p>',
|
|
config: {
|
|
importRules: {
|
|
external: {
|
|
blacklist: {
|
|
'link/mwExternal': false
|
|
}
|
|
}
|
|
}
|
|
},
|
|
msg: 'External links not stripped, but only some protocols allowed'
|
|
}
|
|
];
|
|
|
|
cases.forEach( ve.test.utils.runSurfacePasteTest.bind( this, assert ) );
|
|
} );
|