http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94702
Revision: 94702 Author: brion Date: 2011-08-16 22:42:57 +0000 (Tue, 16 Aug 2011) Log Message: ----------- Fix a regression in search highlighting from r90092 Followup on r94609, r94681 test cases. This fixes the test case with a period that was failing; problem was not the period, but the space before. The changed regex in r90092 ended up including the preceding whitespace in the match, so the position of the match was coming up one character before the actual word -- thus offsetting the highlight by one char. Changed from search to match, using the regex's index property (same as search returns) and adding in the length of the first match component which covers the space/whatever Modified Paths: -------------- trunk/phase3/resources/jquery/jquery.highlightText.js Modified: trunk/phase3/resources/jquery/jquery.highlightText.js =================================================================== --- trunk/phase3/resources/jquery/jquery.highlightText.js 2011-08-16 22:31:22 UTC (rev 94701) +++ trunk/phase3/resources/jquery/jquery.highlightText.js 2011-08-16 22:42:57 UTC (rev 94702) @@ -24,8 +24,9 @@ // non latin characters can make regex think a new word has begun: do not use \b // http://stackoverflow.com/questions/3787072/regex-wordwrap-with-utf8-characters-in-js // look for an occurence of our pattern and store the starting position - var pos = node.data.search( new RegExp( "(^|\\s)" + $.escapeRE( pat ), "i" ) ); - if ( pos >= 0 ) { + var match = node.data.match( new RegExp( "(^|\\s)" + $.escapeRE( pat ), "i" ) ); + if ( match ) { + var pos = match.index + match[1].length; // include length of any matched spaces // create the span wrapper for the matched text var spannode = document.createElement( 'span' ); spannode.className = 'highlight'; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs