Page MenuHomePhabricator

VisualEditor shouldn't change   in sub-reference details
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue:

  • Create a page using the following wikitext:
Test.<ref name="Test" details="S.&nbsp;1">Test&nbsp;Test</ref><ref name="Test2">Test&nbsp;Test2</ref>

== Test ==
Test.<ref name="Test" details="S.&nbsp;2" />

== Einzelnachweise ==
<references />
  • Edit the page using VisualEditor
  • Easiest way to reproduce the bug is by editing the main reference or the sub-reference details.

What happens?:

  • &nbsp; is replaced by a regular space "Non breakable space" character (U+00A0)

Screenshot from 2026-01-21 17-36-08.png (1,064×109 px, 19 KB)

  • The issue only affects content in attributes per T390265#11143908, that's why the main reference doesn't change.
  • For some reason only one sub-reference changes, even if there's no edit to any reference (dewiki example).

What should have happened instead?:

  • Don't replace &nbsp;

Other information:

  • Most sub-references probably don't need &nbsp; given that simple details (e.g. p. 123) are unlikely to be displayed in a way that leads to automatic line breaks. But when contributors use details like quotes in addition to the page number, they may want to intentionally use &nbsp; to prevent automatic line breaks between p. and the page number.

Event Timeline

I've submitted a patch to fix this issue: https://gerrit.wikimedia.org/r/c/mediawiki/services/parsoid/+/1230147

Summary:
The fix adds U+00A0 → &nbsp; conversion during HTML attribute serialization in WikitextSerializer.php. This ensures that non-breaking spaces in attributes (like <ref details="p.&nbsp;123">) are preserved during VisualEditor round-trips instead of being lost.

Implementation:

  • Modified WikitextSerializer.php to detect literal U+00A0 characters in attribute values and convert them back to &nbsp; entities before entity escaping
  • Placed the conversion at the correct point to avoid double-encoding
  • Only affects attribute values; text nodes unchanged

Test coverage:

  • 12 PHPUnit tests (all passing locally)
  • 11 parser tests covering various scenarios
  • Performance validated: negligible impact (~0.036ms per operation)
  • Idempotent and round-trip safe

Please review when you have a chance. Happy to address any feedback!

Change #1230147 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/services/parsoid@master] Parsoid: Preserve `&nbsp;` in attribute serialization

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

Change #1230147 abandoned by Subramanya Sastry:

[mediawiki/services/parsoid@master] Parsoid: Preserve `&nbsp;` in attribute serialization

Reason:

There is nothing salvageable here and the contributor isn't demonstrating any skills or interest in developing them either.

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

Hi @MSantos and @OSleger-WMF ,
This item is a blocker for deploying sub-references to English Wikipedia. Are you planning on working on it in the near future or should we pick it up? Thanks!

Change #1329575 had a related patch set uploaded (by OSleger; author: OSleger):

[mediawiki/services/parsoid@master] Html2Wt: re-encode U+00A0 as &nbsp; in serialized attribute values

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

This task is not a blocker in a literal way. Data are not being lost. Non-breakable space is replace by "literal non-breakable space" character, so final renders are still the same.

I created a patch which can handle this problem at least one way, but it will create problem the other way... Which is by my opinion useful, because I do not believe, that any human would insert U+00A0 instead of &nbsp;. This can create situations, when bot writes U+00A0 into wikitext, in next VE edit of element containing it, it will reverse its effect.

I am not sure RN, what are the proper steps to fix it properly without consulting rest of my team.

Change #1329575 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Html2Wt: re-encode U+00A0 as &nbsp; in serialized attribute values

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

Change #1337625 had a related patch set uploaded (by Jgiannelos; author: Jgiannelos):

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.24.0-a22

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

Change #1337625 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.24.0-a22

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