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

Change subject: Encode as few characters in comments as possible
......................................................................


Encode as few characters in comments as possible

This isn't relevant for Parsoid, but for stand-alone use this will make
VE's output a little bit more idiomatic.

Bug: T95040
Change-Id: Ib0f726e6388da4c0bba7b8ac0ccfc64bd3eee8ac
---
M src/dm/nodes/ve.dm.CommentNode.js
M tests/dm/ve.dm.example.js
2 files changed, 11 insertions(+), 10 deletions(-)

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



diff --git a/src/dm/nodes/ve.dm.CommentNode.js 
b/src/dm/nodes/ve.dm.CommentNode.js
index 054dc34..45c6990 100644
--- a/src/dm/nodes/ve.dm.CommentNode.js
+++ b/src/dm/nodes/ve.dm.CommentNode.js
@@ -60,9 +60,10 @@
                return [ span ];
        } else {
                // Real comment node
-               // Encode & - > (see T95040)
-               data = dataElement.attributes.text.replace( /[-&>]/g, function 
( c ) {
-                       return '&#' + c.charCodeAt(0) + ';';
+               // Encode '&', and certain '-' and '>' characters (see T95040)
+               data = dataElement.attributes.text.replace( /^[->]|--|-$|&/g, 
function ( m ) {
+                       return m.slice( 0, m.length - 1 ) +
+                               '&#' + m.charCodeAt( m.length - 1 ) + ';';
                } );
                return [ doc.createComment( data ) ];
        }
diff --git a/tests/dm/ve.dm.example.js b/tests/dm/ve.dm.example.js
index 4e8e9b4..bd04ba0 100644
--- a/tests/dm/ve.dm.example.js
+++ b/tests/dm/ve.dm.example.js
@@ -2998,29 +2998,29 @@
                fromDataBody: '<div><p>a<b>b</b>c<i>d</i>e</p></div>'
        },
        'comment escaping': {
-               body: '<p><!--Foo&#45;&#45;&#62;b&#38;r--></p>',
+               body: '<p><!--&#45;Foo-bar-&#45;>b&#38;r&#45;--></p>',
                data: [
                        { type: 'paragraph' },
-                       { type: 'comment', attributes: { text: 'Foo-->b&r' } },
+                       { type: 'comment', attributes: { text: 
'-Foo-bar-->b&r-' } },
                        { type: '/comment' },
                        { type: '/paragraph' },
                        { type: 'internalList' },
                        { type: '/internalList' }
                ],
-               clipboardBody: '<p><span rel="ve:Comment" 
data-ve-comment="Foo-->b&amp;r"></span></p>'
+               clipboardBody: '<p><span rel="ve:Comment" 
data-ve-comment="-Foo-bar-->b&amp;r-"></span></p>'
        },
        'comment escaping is normalized': {
-               body: '<p><!--Foo--&gt;b&amp;r--></p>',
+               body: '<p><!--&gt;Foo-bar--&gt;b&amp;r---></p>',
                data: [
                        { type: 'paragraph' },
-                       { type: 'comment', attributes: { text: 'Foo-->b&r' } },
+                       { type: 'comment', attributes: { text: 
'>Foo-bar-->b&r-' } },
                        { type: '/comment' },
                        { type: '/paragraph' },
                        { type: 'internalList' },
                        { type: '/internalList' }
                ],
-               normalizedBody: '<p><!--Foo&#45;&#45;&#62;b&#38;r--></p>',
-               clipboardBody: '<p><span rel="ve:Comment" 
data-ve-comment="Foo-->b&amp;r"></span></p>'
+               normalizedBody: '<p><!--&#62;Foo-bar-&#45;>b&#38;r&#45;--></p>',
+               clipboardBody: '<p><span rel="ve:Comment" 
data-ve-comment=">Foo-bar-->b&amp;r-"></span></p>'
        },
        'other branch nodes': {
                body: '<center>Foo</center><blockquote>Bar</blockquote>',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib0f726e6388da4c0bba7b8ac0ccfc64bd3eee8ac
Gerrit-PatchSet: 6
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Cscott <[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