DLynch has uploaded a new change for review.
https://gerrit.wikimedia.org/r/307324
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(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/24/307324/1
diff --git a/src/dm/lineardata/ve.dm.ElementLinearData.js
b/src/dm/lineardata/ve.dm.ElementLinearData.js
index c44af65..02d9d10 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' && type !==
'preformatted' ) {
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: newchange
Gerrit-Change-Id: I84ccf3b4bdaf4b0fb8f2baf7c87eaf8bcddf518b
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits