Skip to content

Commit ee3b89b

Browse files
committed
UserHighlighterSimple: handle //en.wikipedia.org style URLs
1 parent 1bb0c7e commit ee3b89b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

UserHighlighterSimple/modules/UserHighlighterSimple.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class UserHighlighterSimple {
131131
return false;
132132
}
133133

134+
url = this.addHttpsIfMissing( url );
134135
url = this.addDomainIfMissing( url );
135136

136137
let urlHelper;
@@ -205,6 +206,19 @@ export class UserHighlighterSimple {
205206
url.startsWith( '/', 0 );
206207
}
207208

209+
/**
210+
* URL( url ) expects a complete URL. If we get something like //en.wikipedia.org/wiki/User:Test, convert it to https://en.wikipedia.org/wiki/User:Test.
211+
*
212+
* @param {string} url
213+
* @return {string} url
214+
*/
215+
addHttpsIfMissing( url ) {
216+
if ( url.startsWith( '//' ) ) {
217+
url = this.window.location.protocol + url;
218+
}
219+
return url;
220+
}
221+
208222
/**
209223
* URL( url ) expects a complete URL. If we get something like /wiki/User:Test, convert it to https://en.wikipedia.org/wiki/User:Test. Without this, UserHighlighterSimple doesn't work on metawiki.
210224
*

0 commit comments

Comments
 (0)