Page MenuHomePhabricator

VisualEditor shouldn't change   in sub-reference details
Open, Needs TriagePublicBUG 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

Screenshot from 2026-01-21 17-36-08.png (109×1 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