Fix exceptions on weirdly encoded URLs

`decodeURI( fragment )` can throw if the fragment isn't correctly
encoded – e.g. when it's just '#%'.

Use mw.util.percentDecodeFragment() instead, which uses a more
resilient algorithm.

Change-Id: I8447771ad2ae33da52b71d4127981dd8a2018a7d
This commit is contained in:
Bartosz Dziewoński 2024-02-03 23:48:54 +01:00
parent 9f650c92ee
commit 1bb3b597ec

View file

@ -592,14 +592,14 @@ function init( $container, state ) {
return !pattern.test( fragment );
} ) ) {
findCommentQuery = {
heading: decodeURI( fragment ).replace( / /g, '_' ),
heading: mw.util.percentDecodeFragment( fragment ).replace( / /g, '_' ),
page: mw.config.get( 'wgRelevantPageName' )
};
isHeading = true;
}
} else if ( highlightResult.highlighted.length === 0 && highlightResult.requested.length === 1 ) {
findCommentQuery = {
idorname: decodeURI( highlightResult.requested[ 0 ] )
idorname: mw.util.percentDecodeFragment( highlightResult.requested[ 0 ] )
};
isHeading = highlightResult.requested[ 0 ].slice( 0, 1 ) === 'h';
}