r97606 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97605‎ | r97606 | r97607 >
Date:08:56, 20 September 2011
Author:junaidpv
Status:ok (Comments)
Tags:
Comment:
Narayam: Blank keybuffer was matching against rules that require keybuffer match. Fixed now.
Modified paths:
  • /trunk/extensions/Narayam/js/ext.narayam.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/js/ext.narayam.core.js
@@ -53,13 +53,19 @@
5454 var rules = currentScheme.extended_keyboard && useExtended ?
5555 currentScheme.rules_x : currentScheme.rules;
5656 for ( var i = 0; i < rules.length; i++ ) {
57 - var keyBufferMatch = true;
58 - if ( rules[i][1].length > 0 && rules[i][1].length <= keyBuffer.length ) {
59 - // Try to match rules[i][1] at the end of the key buffer
60 - keyBufferMatch = new RegExp( rules[i][1] + '$' ).test( keyBuffer );
61 - }
6257 var regex = new RegExp( rules[i][0] + '$' );
63 - if ( keyBufferMatch && regex.test( str ) ) {
 58+ if ( regex.test( str ) // Input string match
 59+ &&
 60+ (
 61+ rules[i][1].length == 0 // Keybuffer match not required
 62+ ||
 63+ ( // Keybuffer match specified, so it should be met
 64+ rules[i][1].length > 0
 65+ && rules[i][1].length <= keyBuffer.length
 66+ && new RegExp( rules[i][1] + '$' ).test( keyBuffer )
 67+ )
 68+ )
 69+ ) {
6470 return str.replace( regex, rules[i][2] );
6571 }
6672 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r981441.17wmf1: MFT r97606, r97609, r97644, r97793, r97804, r97962, r98006, r98023catrope17:21, 26 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   13:52, 22 September 2011

Test cases would be nice. As it is I can't understand what the code is doing.

#Comment by Santhosh.thottingal (talk | contribs)   09:28, 23 September 2011

f ( keyBufferMatch && regex.test( str ) ) - this condition was doing input string matching and keyBufferMatch assertion. Now keyBufferMatch is doing only after regex.test( str is passed, there by avoid unnecessary checks even if keybuffer is empty or even the rule does not match with input string itself.

Status & tagging log