Page MenuHomePhabricator

mw.Uri cannot be called on subpages (TypeError: Cannot read property 'protocol' of undefined)
Closed, DuplicatePublic

Description

On https://en.wikipedia.org/wiki/Wikipedia:Reference_desk/Science?debug=true#Is_it_night_50%_of_the_time_on_average_everywhere? a JS error occurs.

https://logstash.wikimedia.org/app/dashboards#/doc/logstash-*/logstash-2021.02.24?id=xp8k1ncBg_6mGHGhXBpB

Not sure if this is a VE error or a mediawiki.Uri error.

mw.config.get( 'wgRelevantPageName' )
"Wikipedia:Reference_desk/Science"
mw.util.getUrl( mw.config.get( 'wgRelevantPageName' ) )
"/wiki/Wikipedia:Reference_desk/Science"
new mw.Uri( mw.util.getUrl( mw.config.get( 'wgRelevantPageName' ) ) )
TypeError: Cannot read property 'protocol' of undefined

The code in question is:

conf = mw.config.get( 'wgVisualEditorConfig' );
	tabMessages = conf.tabMessages;
	viewUri = new mw.Uri( mw.util.getUrl( mw.config.get( 'wgRelevantPageName' ) ) ); // <<< problematic line
	try {
		uri = new mw.Uri( null, { arrayParams: true } );
	} catch ( e ) {
		// URI failed to parse, probably because of query string parameters. (T270331)
		// Fall back to the viewUri so that initialization completes.
		// Ideally mw.Uri would ignore invalid parameters or characters.
		uri = viewUri;
	}

Event Timeline

This has nothing to do with subpages, or with VisualEditor. mw.Uri crashes when there's an un-encoded '%' character in the URL. This is the exact same issue as T269948 or T268060. It should be tracked and fixed as a bug in mw.Uri, not in a hundred random extensions that use that code.