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

Change subject: ElementLinearData: don't sanitize away newlines within <pre>
......................................................................


ElementLinearData: don't sanitize away newlines within <pre>

We were assuming that newlines are semantically meaningless. This is generally
true, unless we're inside a preformatted block, in which case they do matter.
In that case, let them be.

Bug: T132006
Change-Id: I84ccf3b4bdaf4b0fb8f2baf7c87eaf8bcddf518b
---
M src/dm/lineardata/ve.dm.ElementLinearData.js
M tests/dm/lineardata/ve.dm.ElementLinearData.test.js
2 files changed, 17 insertions(+), 1 deletion(-)

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



diff --git a/src/dm/lineardata/ve.dm.ElementLinearData.js 
b/src/dm/lineardata/ve.dm.ElementLinearData.js
index c44af65..58f300c 100644
--- a/src/dm/lineardata/ve.dm.ElementLinearData.js
+++ b/src/dm/lineardata/ve.dm.ElementLinearData.js
@@ -1112,7 +1112,9 @@
                        // Remove plain newline characters, as they are 
semantically meaningless
                        // and will confuse the user. Firefox adds these 
automatically when copying
                        // line-wrapped HTML. T104790
-                       if ( this.getCharacterData( i ) === '\n' ) {
+                       // However, don't remove them if we're in a situation 
where they might
+                       // actually be meaningful -- i.e. if we're inside a 
<pre>. T132006
+                       if ( this.getCharacterData( i ) === '\n' && 
!ve.dm.nodeFactory.doesNodeHaveSignificantWhitespace( type ) ) {
                                if ( this.getCharacterData( i + 1 ).match( /\s/ 
) || this.getCharacterData( i - 1 ).match( /\s/ ) ) {
                                        // If whitespace-adjacent, remove the 
newline to avoid double spaces
                                        this.splice( i, 1 );
diff --git a/tests/dm/lineardata/ve.dm.ElementLinearData.test.js 
b/tests/dm/lineardata/ve.dm.ElementLinearData.test.js
index c73ee08..ad738b2 100644
--- a/tests/dm/lineardata/ve.dm.ElementLinearData.test.js
+++ b/tests/dm/lineardata/ve.dm.ElementLinearData.test.js
@@ -1690,6 +1690,20 @@
                                msg: 'Newline characters are stripped and 
replaced with spaces where necessary'
                        },
                        {
+                               html: '<p>Foo\nBar\n <pre>Baz \nQuux</pre></p>',
+                               data: [
+                                       { type: 'paragraph' },
+                                       'F', 'o', 'o', ' ', 'B', 'a', 'r',
+                                       { type: '/paragraph' },
+                                       { type: 'preformatted' },
+                                       'B', 'a', 'z', ' ', '\n', 'Q', 'u', 
'u', 'x',
+                                       { type: '/preformatted' },
+                                       { type: 'internalList' },
+                                       { type: '/internalList' }
+                               ],
+                               msg: 'Newline characters are not stripped when 
they are meaningful'
+                       },
+                       {
                                html: '<p>Foo</p> \n\t <p>Bar</p>',
                                data: [
                                        { type: 'paragraph' },

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I84ccf3b4bdaf4b0fb8f2baf7c87eaf8bcddf518b
Gerrit-PatchSet: 2
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <[email protected]>
Gerrit-Reviewer: DLynch <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to