Page MenuHomePhabricator

Parsoid incorrectly parses links to pages starting with a slash '/' in namespaces that can have subpages
Closed, ResolvedPublic

Description

Parsoid incorrectly parses links to pages starting with a slash '/' in namespaces that can have subpages. Trying to link to (for example) page called "/B" instead generates links to the "B" subpage of the current page.

Transformation is incorrect in both directions:

(assuming page title is User:Matma_Rex/sandbox, tested via https://en.wikipedia.org/api/rest_v1/)

Input<a href=".//B" rel="mw:WikiLink">/B</a>
Actual output[[/B]]
Expected output[[:/B]]
Input[[:/B]]
Actual output<a rel="mw:WikiLink" href="./User:Matma_Rex/sandbox/B" title="User:Matma Rex/sandbox/B" id="mwAw" class="new">/B</a>
Expected output<a rel="mw:WikiLink" href=".//B" title="/B" id="mwAw" class="new">/B</a>

Event Timeline

ssastry triaged this task as Medium priority.Apr 15 2019, 8:50 PM
ssastry edited projects, added: Parsoid-Read-Views-Deprecated-Project; removed: Parsoid.

I think the suggested behavior here is far less likely to be what people intended than the subpage behavior. Pages whose names start with a / are unusual, and I suspect people are more likely to be trying to link to a subpage.

As I said over in T110413, .//Foo is pretty dubious as an href. But then again, https://en.wikipedia.org/wiki//e/_(operating_system) exists on enwiki, so I guess that's legit.

https://en.wikipedia.org/wiki/User:Cscott/task221028 shows some of the possibilities.

https://en.wikipedia.org/wiki/Special:ApiSandbox#action=visualeditor&format=json&page=User%3ACscott%2Ftask221028&paction=parse&utf8=1&formatversion=latest seems to confirm that Parsoid is handling the [[: prefix incorrectly.

I think this is related to this task: links like [[:/dev/zero]] should point to a page called /dev/zero in the main namespace, not to a subpage of the current page. This is not respected by Parsoid, though, and links like these show up as linking to a subpage.

My testcase: https://en.wikipedia.org/wiki/User:Ostrzyciel/slash_test

Output of the main parser:

image.png (375×86 px, 5 KB)

Appearance in VE when editing:

image.png (549×297 px, 18 KB)

Now this I would consider a serious issue, as there are multiple articles starting with a forward slash on Wikipedia: https://en.wikipedia.org/wiki/Special:PrefixIndex?prefix=%2F&namespace=0&hideredirects=1

T226289 seems to be in the same area and should be solved together

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

[mediawiki/services/parsoid@master] Handle colon prefixed links in NSs that allow subpages

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

Change #1305869 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Handle slash prefixed links in NSs that allow subpages

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

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

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

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

Change #1310144 merged by jenkins-bot:

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

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

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

[mediawiki/vendor@wmf/1.47.0-wmf.11] Bump wikimedia/parsoid to 0.24.0-a15

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

Change #1312554 merged by jenkins-bot:

[mediawiki/vendor@wmf/1.47.0-wmf.11] Bump wikimedia/parsoid to 0.24.0-a15

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

Mentioned in SAL (#wikimedia-operations) [2026-07-20T20:17:16Z] <arlolra@deploy2003> Started scap sync-world: Backport for [[gerrit:1312547|Enable PRV on enwiki talk namespace, template namespace]], [[gerrit:1312554|Bump wikimedia/parsoid to 0.24.0-a15 (T221028 T226289 T353697 T430854 T431771)]], [[gerrit:1312556|Bump wikimedia/parsoid to 0.24.0-a15 (T431771)]]

Mentioned in SAL (#wikimedia-operations) [2026-07-20T20:20:59Z] <arlolra@deploy2003> arlolra, cscott: Backport for [[gerrit:1312547|Enable PRV on enwiki talk namespace, template namespace]], [[gerrit:1312554|Bump wikimedia/parsoid to 0.24.0-a15 (T221028 T226289 T353697 T430854 T431771)]], [[gerrit:1312556|Bump wikimedia/parsoid to 0.24.0-a15 (T431771)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2026-07-20T20:32:24Z] <arlolra@deploy2003> Finished scap sync-world: Backport for [[gerrit:1312547|Enable PRV on enwiki talk namespace, template namespace]], [[gerrit:1312554|Bump wikimedia/parsoid to 0.24.0-a15 (T221028 T226289 T353697 T430854 T431771)]], [[gerrit:1312556|Bump wikimedia/parsoid to 0.24.0-a15 (T431771)]] (duration: 15m 07s)

ABreault-WMF subscribed.

Post-deploy and purge, the [[:/dev/zero]] is rendered as a blue link on
https://en.wikipedia.org/wiki/User:Ostrzyciel/slash_test?useparsoid=1


From the task description,

curl -X 'POST' \
  'https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html/User%3AMatma_Rex%2Fsandbox' \
  -H 'accept: text/html; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/HTML/2.1.0"' \
  -H 'Content-Type: multipart/form-data' \
  -F 'wikitext=[[:/B]]' \
  -F 'body_only=true' \
  -F 'stash=true'

now yields

<p id="mwAg"><a rel="mw:WikiLink" href=".//B?action=edit&amp;redlink=1" title="/B" class="new" typeof="mw:LocalizedAttrs" id="mwAw" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["/B"]}}'>/B</a></p>

and

curl -X 'POST' \
  'https://en.wikipedia.org/api/rest_v1/transform/html/to/wikitext/User%3AMatma_Rex%2Fsandbox' \
  -H 'accept: text/plain; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0"' \
  -H 'Content-Type: multipart/form-data' \
  -F 'html=<a href='\''.//B'\'' rel='\''mw:WikiLink'\''>/B</a>' \
  -F 'scrub_wikitext=true'

now yields

[[:/B]]