From f3b7ccdefb1655cd1d93f7642ee98b28aa94700f Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 30 Mar 2015 21:57:35 -0700 Subject: [PATCH] Use ve.safeDecodeURIComponent() Depends on Iacc50230a in VE core. Change-Id: I7fc505c261726f8d83c86a9cc352a0bf9fcb455a --- modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js | 2 +- .../dm/annotations/ve.dm.MWInternalLinkAnnotation.js | 4 ++-- modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js | 8 ++++---- modules/ve-mw/dm/nodes/ve.dm.MWImageNode.js | 8 +------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js index a591715e8b..94932bd8b9 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js @@ -172,7 +172,7 @@ ve.ce.MWTransclusionNode.prototype.getRenderedDomElements = function ( domElemen var targetData = ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref( this.href, transclusionNode.getModelHtmlDocument() ), - normalisedHref = decodeURIComponent( targetData.title ); + normalisedHref = ve.safeDecodeURIComponent( targetData.title ); if ( mw.Title.newFromText( normalisedHref ) ) { normalisedHref = mw.Title.newFromText( normalisedHref ).getPrefixedText(); } diff --git a/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js b/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js index 7be92c34a3..99bc4abc58 100644 --- a/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js +++ b/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js @@ -42,7 +42,7 @@ ve.dm.MWInternalLinkAnnotation.static.toDataElement = function ( domElements, co type: this.name, attributes: { hrefPrefix: targetData.hrefPrefix, - title: decodeURIComponent( targetData.title ).replace( /_/g, ' ' ), + title: ve.safeDecodeURIComponent( targetData.title ).replace( /_/g, ' ' ), normalizedTitle: this.normalizeTitle( targetData.title ), lookupTitle: this.getLookupTitle( targetData.title ), origTitle: targetData.title @@ -92,7 +92,7 @@ ve.dm.MWInternalLinkAnnotation.static.getHref = function ( dataElement ) { var href, title = dataElement.attributes.title, origTitle = dataElement.attributes.origTitle; - if ( origTitle !== undefined && decodeURIComponent( origTitle ).replace( /_/g, ' ' ) === title ) { + if ( origTitle !== undefined && ve.safeDecodeURIComponent( origTitle ).replace( /_/g, ' ' ) === title ) { // Restore href from origTitle href = origTitle; // Only use hrefPrefix if restoring from origTitle diff --git a/modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js b/modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js index f0c6f3a457..ad56235169 100644 --- a/modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js +++ b/modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js @@ -41,9 +41,9 @@ ve.dm.MWCategoryMetaItem.static.toDataElement = function ( domElements ) { type: this.name, attributes: { hrefPrefix: matches[1], - category: decodeURIComponent( matches[2] ).replace( /_/g, ' ' ), + category: ve.safeDecodeURIComponent( matches[2] ).replace( /_/g, ' ' ), origCategory: matches[2], - sortkey: decodeURIComponent( rawSortkey ).replace( /_/g, ' ' ), + sortkey: ve.safeDecodeURIComponent( rawSortkey ).replace( /_/g, ' ' ), origSortkey: rawSortkey } }; @@ -57,8 +57,8 @@ ve.dm.MWCategoryMetaItem.static.toDomElements = function ( dataElement, doc ) { sortkey = dataElement.attributes.sortkey || '', origCategory = dataElement.attributes.origCategory || '', origSortkey = dataElement.attributes.origSortkey || '', - normalizedOrigCategory = decodeURIComponent( origCategory ).replace( /_/g, ' ' ), - normalizedOrigSortkey = decodeURIComponent( origSortkey ).replace( /_/g, ' ' ); + normalizedOrigCategory = ve.safeDecodeURIComponent( origCategory ).replace( /_/g, ' ' ), + normalizedOrigSortkey = ve.safeDecodeURIComponent( origSortkey ).replace( /_/g, ' ' ); if ( normalizedOrigSortkey === sortkey ) { sortkey = origSortkey; } else { diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWImageNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWImageNode.js index ebb6e71d95..55a307a86f 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWImageNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWImageNode.js @@ -206,13 +206,7 @@ ve.dm.MWImageNode.prototype.getFilename = function () { var resource = this.getAttribute( 'resource' ) || '', filename = resource.replace( /^(\.+\/)*/, '' ); - // Protect against decodeURIComponent() throwing exceptions - try { - filename = decodeURIComponent( filename ); - } catch ( e ) { - ve.log( 'URI decoding exception', e ); - } - return filename; + return ve.safeDecodeURIComponent( filename ); }; /**