r114331 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114330‎ | r114331 | r114332 >
Date:23:31, 20 March 2012
Author:rsterbin
Status:resolved
Tags:
Comment:
Followup to 114064; updated regex to avoid cascading replacements and catch two-digit replacement codes
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
@@ -2914,20 +2914,23 @@
29152915 */
29162916 $.articleFeedbackv5.buildLink = function ( fulltext, link1, link2, link3 ) {
29172917 var full = mw.html.escape( mw.msg( fulltext ) );
2918 - for ( var i = 1; i < arguments.length; i++ ) {
2919 - var sub = arguments[i];
2920 - var re = new RegExp("\\$" + i, 'g');
 2918+ var args = arguments;
 2919+ return full.replace( /\$(\d+)/g, function( str, number ) {
 2920+ var i = parseInt( number, 10 );
 2921+ var sub = args[i];
 2922+ var replacement = '';
29212923 if ( sub.tag == 'quotes' ) {
2922 - full = full.replace( re, '&quot;' + mw.msg( sub.text ) + '&quot' );
 2924+ replacement = '&quot;' + mw.msg( sub.text ) + '&quot';
29232925 } else {
2924 - full = full.replace( re, mw.html.element(
 2926+ replacement = mw.html.element(
29252927 'tag' in sub ? sub.tag : 'a',
29262928 $.articleFeedbackv5.attribs( sub ),
29272929 mw.msg( sub.text )
2928 - ).toString() );
 2930+ ).toString();
29292931 }
2930 - }
2931 - return full;
 2932+ console.log(replacement);
 2933+ return replacement;
 2934+ } );
29322935 };
29332936
29342937 // }}}

Follow-up revisions

RevisionCommit summaryAuthorDate
r114377Remove stray console.log() introduced in r114331catrope17:09, 21 March 2012

Status & tagging log