Page MenuHomePhabricator

Parsoid renders template as comment, breaking serialization
Closed, ResolvedPublic


I simply deleted a word from the leading paragraph in the article below, and got this as diff:

To reproduce: Revert to the previous version in that diff, edit the article in VE, and delete a word from the leading paragraph.

Version: unspecified
Severity: normal



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:37 AM
bzimport added a project: Parsoid.
bzimport set Reference to bz54927.
Mooeypoo created this task.Oct 3 2013, 5:56 PM

This is due to a Parsoid bug.

Example that Moriel gave me:

HTML starts with:

\\n\",\"href\":\"./תבנית:שחקנים\"},\"params\":{\"שם\":{\"wt\":\"דניאל רדקליף\"},\"תמונה\":{\"wt\":\"[[קובץ:Daniel Radcliffe Paris 2012.jpg|200px]]\"},\"כיתוב\":{\"wt\":\"<small> דניאל רדקליף, [[2012]]</small>\"},\"תאריך לידה\":{\"wt\":\"23 ביולי 1989\"},\"מקום לידה\":{\"wt\":\"[[לונדון]], [[אנגליה]], [[הממלכה המאוחדת]]\"},\"כינוי\":{\"wt\":\"דן\"},\"דמות\":{\"wt\":\"[[הארי פוטר (דמות)|הארי פוטר]]\"},\"בכורה\":{\"wt\":\"בסדרה [[דייוויד קופרפילד]], 1999\"},\"אתר אינטרנט\":{\"wt\":\"\"},\"קישור\":{\"wt\":\"0705356\"}}},\"paramInfos\":[{\"k\":\"שם\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"
\\n\"]},{\"k\":\"תמונה\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]},{\"k\":\"כיתוב\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]},{\"k\":\"תאריך לידה\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]},{\"k\":\"מקום לידה\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]},{\"k\":\"כינוי\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]},{\"k\":\"דמות\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]},{\"k\":\"בכורה\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]},{\"k\":\"אתר אינטרנט\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]},{\"k\":\"קישור\",\"named\":true,\"spc\":[\"\",\"\",\"\",\"\\n\"]}]}"},{"name":"data-parsoid","value":"{\"tsr\":[0,356],\"src\":\"{{שחקנים
\\n|שם=דניאל רדקליף
\\n|תמונה=[[קובץ:Daniel Radcliffe Paris 2012.jpg|200px]]\\n|כיתוב=<small> דניאל רדקליף, [[2012]]</small>\\n|תאריך לידה=23 ביולי 1989\\n|מקום לידה=[[לונדון]], [[אנגליה]], [[הממלכה המאוחדת]]\\n|כינוי=דן\\n|דמות=[[הארי פוטר (דמות)|הארי פוטר]]\\n|בכורה=בסדרה [[דייוויד קופרפילד]], 1999\\n|אתר אינטרנט=\\n|קישור=0705356\\n}}\",\"tagId\":1}"}]}-->
<table class="infobox" style="width:18em; font-size:85%;" cellspacing="5" about="#mwt1" data-parsoid="{}">[....]</table>
<meta typeof="mw:Transclusion/End" about="#mwt1" data-parsoid="{&quot;dsr&quot;:[null,356,null,null]}">

Note how:

  • The transclusion starts with a comment (!) which tries to be in the #mwt1 about group
  • The transclusion continues with a table in that same about group
  • The about group ends with a meta tag in that same about group

This doesn't serialize cleanly at all, the template gets inserted into the wikitext and the table gets serialized as wikitext as well. Even the <meta> tag gets serialized:

In VisualEditor, this causes:

  • corruption on save like in the diff Moriel linked
  • the user to be able to edit inside the infobox, because the comment is ignored and there are no attributes on the <table> telling VE it's part of a template (there's about="#mwt1" but that doesn't refer back to a valid about group, so it's interpreted as the start of an about group)

The problem here is that the contents of that comment isn't matching this regex,

/^\{.*\}$/.test( content )

It's not recognizing the last character as }. Taking content.charCodeAt( content.length - 1 ) returns undefined. Probably because of the unicode characters. Switching to something like,

/^\{\"@type\"/.test( content )

seems to work but I'm interested to see where exactly things are going wrong.

On second thought, I think it's because . doesn't match newline chars.

Change 90687 had a related patch set uploaded by Arlolra:
Match all characters when testing comments for JSON

Change 90687 merged by jenkins-bot:
Match all characters when testing comments for JSON

  • Bug 56722 has been marked as a duplicate of this bug. ***