Merge "Move possibly expensive title parser construction down"

This commit is contained in:
jenkins-bot 2019-02-11 22:28:19 +00:00 committed by Gerrit Code Review
commit 5752b3feb1
3 changed files with 3 additions and 4 deletions

Binary file not shown.

Binary file not shown.

View file

@ -12,9 +12,6 @@ const mw = mediaWiki;
* @return {string|undefined}
*/
export function getTitle( href, config ) {
const titleRegex = new RegExp( mw.RegExp.escape( config.get( 'wgArticlePath' ) )
.replace( '\\$1', '([^?#]+)' ) );
// Skip every URI that mw.Uri cannot parse
let linkHref;
try {
@ -33,7 +30,9 @@ export function getTitle( href, config ) {
// No query params (pretty URL)
if ( !queryLength ) {
const matches = titleRegex.exec( linkHref.path );
const pattern = mw.RegExp.escape( config.get( 'wgArticlePath' ) ).replace( '\\$1', '([^?#]+)' ),
matches = new RegExp( pattern ).exec( linkHref.path );
// We can't be sure decodeURIComponent() is able to parse every possible match
try {
title = matches && decodeURIComponent( matches[ 1 ] );