Page MenuHomePhabricator

mw.util.getUrl changes double $ signs to a single $ sign
Closed, ResolvedPublic

Description

> mw.util.getUrl('Test$$hello$$')
"/wiki/Test$hello$"

Event Timeline

The problem is at this line:

url = mw.config.get( 'wgArticlePath' ).replace( '$1', util.wikiUrlencode( title ) );

Exactly in the String.replace function. $$ comes in the replacement string, which has a special meaning. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter

The fix would be something so simple and awkward as this:

url = mw.config.get( 'wgArticlePath' ).replace( '$1', util.wikiUrlencode( title ).replace(/\$/g,'$$$$') );

Change 319266 had a related patch set uploaded (by TTO):
mediawiki.util: Fix replacement of $ signs in mw.util.getUrl

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

Thanks for the sleuthing work!

matmarex assigned this task to TTO.
matmarex removed a project: Patch-For-Review.

Good catch.

An alternative is:

url = mw.config.get( 'wgArticlePath' ).replace( '$1', function () {
	return util.wikiUrlencode( title );
} );

Change 319266 merged by jenkins-bot:
mediawiki.util: Fix replacement of $ signs in mw.util.getUrl

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