mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Change mw.libs.ve.getTargetDataFromHref to not return bogus data for external links
For external links, `.title` and `.rawTitle` properties previously contained the external link corrupted with some normalization intended for MediaWiki titles. This was useless, and in fact no caller actually uses this value: they all check `.isInternal` first before accessing `.title` or `.rawTitle`. Also, correct other parameter documentation. Change-Id: Ieeab56548f0a3b2f81a90f0d3ae0f81d744aa67b
This commit is contained in:
parent
9c25161966
commit
b6929d5be1
|
@ -261,12 +261,12 @@ mw.libs.ve.fixFragmentLinks = function ( container, docTitle, prefix ) {
|
|||
* Parse URL to get title it points to.
|
||||
*
|
||||
* @param {string} href
|
||||
* @param {HTMLDocument|string} doc Document whose base URL to use, or base URL as a string.
|
||||
* @param {HTMLDocument} doc Document whose base URL to use
|
||||
* @return {Object} Information about the given href
|
||||
* @return {string} return.title
|
||||
* The title of the internal link, else the original href if href is external
|
||||
* @return {string} return.rawTitle
|
||||
* The title without URL decoding and underscore normalization applied
|
||||
* @return {string} [return.title]
|
||||
* The title of the internal link (if the href is internal)
|
||||
* @return {string} [return.rawTitle]
|
||||
* The title without URL decoding and underscore normalization applied (if the href is internal)
|
||||
* @return {boolean} return.isInternal
|
||||
* True if the href pointed to the local wiki, false if href is external
|
||||
*/
|
||||
|
@ -342,10 +342,14 @@ mw.libs.ve.getTargetDataFromHref = function ( href, doc ) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( !isInternal ) {
|
||||
return { isInternal: false };
|
||||
}
|
||||
|
||||
// This href doesn't necessarily come from Parsoid (and it might not have the "./" prefix), but
|
||||
// this method will work fine.
|
||||
var data = mw.libs.ve.parseParsoidResourceName( href );
|
||||
data.isInternal = isInternal;
|
||||
data.isInternal = true;
|
||||
return data;
|
||||
};
|
||||
|
||||
|
|
|
@ -109,8 +109,6 @@ QUnit.test( 'getTargetDataFromHref', ( assert ) => {
|
|||
msg: 'Valid protocol is handled as external link',
|
||||
href: 'https://example.net/',
|
||||
expectedInfo: {
|
||||
title: 'https://example.net/',
|
||||
rawTitle: 'https://example.net/',
|
||||
isInternal: false
|
||||
}
|
||||
},
|
||||
|
@ -118,8 +116,6 @@ QUnit.test( 'getTargetDataFromHref', ( assert ) => {
|
|||
msg: 'Valid protocol is handled as external link',
|
||||
href: 'mailto:example@example.net',
|
||||
expectedInfo: {
|
||||
title: 'mailto:example@example.net',
|
||||
rawTitle: 'mailto:example@example.net',
|
||||
isInternal: false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue