Esanders has uploaded a new change for review.

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

Change subject: Don't encoding single hyphens in comments, just doubles
......................................................................

Don't encoding single hyphens in comments, just doubles

Single hyphens are common and not invalid XML.

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


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/11/202711/1

diff --git a/src/dm/nodes/ve.dm.CommentNode.js 
b/src/dm/nodes/ve.dm.CommentNode.js
index 054dc34..5f460cf 100644
--- a/src/dm/nodes/ve.dm.CommentNode.js
+++ b/src/dm/nodes/ve.dm.CommentNode.js
@@ -60,9 +60,11 @@
                return [ span ];
        } else {
                // Real comment node
-               // Encode & - > (see T95040)
-               data = dataElement.attributes.text.replace( /[-&>]/g, function 
( c ) {
-                       return '&#' + c.charCodeAt(0) + ';';
+               // Encode '&', '--' and '>' (see T95040)
+               data = dataElement.attributes.text.replace( /(--|&|>)/g, 
function ( match ) {
+                       return match.split( '' ).map( function ( c ) {
+                               return '&#' + c.charCodeAt( 0 ) + ';';
+                       } ).join( '' );
                } );
                return [ doc.createComment( data ) ];
        }
diff --git a/tests/dm/ve.dm.example.js b/tests/dm/ve.dm.example.js
index 05f5f28..351c0eb 100644
--- a/tests/dm/ve.dm.example.js
+++ b/tests/dm/ve.dm.example.js
@@ -2998,16 +2998,16 @@
                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><!--Foo-bar&#45;&#45;&#62;b&#38;z--></p>',
                data: [
                        { type: 'paragraph' },
-                       { type: 'comment', attributes: { text: 'Foo-->b&r' } },
+                       { type: 'comment', attributes: { text: 'Foo-bar-->b&z' 
} },
                        { 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;z"></span></p>'
        },
        'comment escaping is normalized': {
                body: '<p><!--Foo--&gt;b&amp;r--></p>',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib0f726e6388da4c0bba7b8ac0ccfc64bd3eee8ac
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to