Use browser native URL instead of mw.Uri

Bug: T374314
Change-Id: I66be10c017e853ea130b0919789b22c4c3f12622
This commit is contained in:
Ebrahim Byagowi 2024-09-10 13:09:33 +03:30
parent 6bf48eee89
commit 475f80cf76
3 changed files with 14 additions and 5 deletions

View file

@ -124,9 +124,9 @@ function getWprovFromResultIndex( index ) {
function addWprovToSearchResultUrls( results, offset ) {
return results.map( ( result, index ) => {
if ( result.url ) {
const uri = new mw.Uri( result.url );
uri.query.wprov = getWprovFromResultIndex( index + offset );
result = Object.assign( {}, result, { url: uri.toString() } );
const url = new URL( result.url, location.href );
url.searchParams.set( 'wprov', getWprovFromResultIndex( index + offset ) );
result = Object.assign( {}, result, { url: url.toString() } );
}
return result;
} );

View file

@ -230,7 +230,7 @@
},
"skins.vector.search": {
"dependencies": [
"mediawiki.Uri",
"web2017-polyfills",
"mediawiki.util",
"skins.vector.search.codex.scripts"
],

View file

@ -13,7 +13,8 @@ describe( 'instrumentation', () => {
test( 'addWprovToSearchResultUrls without offset', () => {
const url1 = 'https://host/?title=Special%3ASearch&search=Aa',
url2Base = 'https://host/?title=Special%3ASearch&search=Ab',
url3 = 'https://host/Ac';
url3 = 'https://host/Ac',
url5 = '/index.php?title=Special%3ASearch&search=Ad';
const results = [
{
title: 'Aa',
@ -29,6 +30,10 @@ describe( 'instrumentation', () => {
},
{
title: 'Ad'
},
{
title: 'Ae',
url: url5
}
];
@ -48,6 +53,10 @@ describe( 'instrumentation', () => {
},
{
title: 'Ad'
},
{
title: 'Ae',
url: `${ location.origin }${ url5 }&wprov=acrw1_4`
}
] );
expect( results[ 0 ].url ).toStrictEqual( url1 );