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

TTO created this task.Nov 2 2016, 2:39 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 2 2016, 2:39 AM

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

TTO added a comment.Nov 2 2016, 3:22 AM

Thanks for the sleuthing work!

matmarex closed this task as Resolved.Nov 2 2016, 9:49 AM
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