Catrope has uploaded a new change for review.

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


Change subject: Fix a weird whitespace stripping bug
......................................................................

Fix a weird whitespace stripping bug

In HTML like <td>Foo <b>Bar</b></td>, the space would be stripped and
registered as trailing whitespace in the <td>, so it wouldn't be visible
in the editor and would be inserted after the </b> on the way out.

Thanks to Subbu for reporting this. This case was kind of ridiculous and
we're lucky the JRuby article contained it. To trigger the bug, you had
to have:
* a table cell
* containing unwrapped content
* consisting of
** some text
** whitespace
** open annotation (bold in my example, link in Subbu's case)
** text
** close annotation
** and nothing else

Change-Id: I2b83f02764b311a32a50956d4c8930a9394e91a4
---
M modules/ve/dm/ve.dm.Converter.js
M modules/ve/test/dm/ve.dm.example.js
2 files changed, 24 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/70/59770/1

diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index 9a49c2e..d03fc0f 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -462,6 +462,8 @@
                                        data = data.concat(
                                                this.getDataFromDomRecursion( 
childDomElement, undefined, childAnnotations )
                                        );
+                                       // Clear wrapped whitespace
+                                       wrappedWhitespace = '';
                                } else {
                                        // Node or meta item
                                        if ( modelClass.prototype instanceof 
ve.dm.MetaItem ) {
diff --git a/modules/ve/test/dm/ve.dm.example.js 
b/modules/ve/test/dm/ve.dm.example.js
index 2a04071..6a2e07a 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -1652,6 +1652,28 @@
                // comparing DOM trees
                'normalizedHtml': 
'<body>\n<pre>\n\n\n\nFoo\n\n\nBar\n\n\n\n</pre>\n\n\n\n\n</body>'
        },
+       'whitespace preservation in table cell starting with text and ending 
with annotation': {
+               'html': '<body><table><tbody><tr><td>Foo 
<b>Bar</b></td></tr></tbody></table></body>',
+               'data': [
+                       { 'type': 'table' },
+                       { 'type': 'tableSection', 'attributes': { 'style': 
'body' } },
+                       { 'type': 'tableRow' },
+                       { 'type': 'tableCell', 'attributes': { 'style': 'data' 
} },
+                       { 'type': 'paragraph', 'internal': { 'generated': 
'wrapper' } },
+                       'F',
+                       'o',
+                       'o',
+                       ' ',
+                       [ 'B', [ ve.dm.example.bold ] ],
+                       [ 'a', [ ve.dm.example.bold ] ],
+                       [ 'r', [ ve.dm.example.bold ] ],
+                       { 'type': '/paragraph' },
+                       { 'type': '/tableCell' },
+                       { 'type': '/tableRow' },
+                       { 'type': '/tableSection' },
+                       { 'type': '/table' }
+               ]
+       },
        'mismatching whitespace data is ignored': {
                'html': null,
                'data': [

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2b83f02764b311a32a50956d4c8930a9394e91a4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

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

Reply via email to