Divec has uploaded a new change for review. https://gerrit.wikimedia.org/r/216061
Change subject: At empty matches, don't assume lastIndex is unchanged ...................................................................... At empty matches, don't assume lastIndex is unchanged It seems that Internet Explorer increments lastIndex for empty matches (see http://blog.stevenlevithan.com/archives/exec-bugs ), whereas Firefox and Chromium do not. I can't think of a simple way to unit test this code (i.e. short of coding up something with Object.defineProperty). Change-Id: I87ee908021a95c9b1d08f463c2606dc90dbf8f1f --- M src/dm/ve.dm.Document.js 1 file changed, 10 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/61/216061/1 diff --git a/src/dm/ve.dm.Document.js b/src/dm/ve.dm.Document.js index 724d9eb..e79c674 100644 --- a/src/dm/ve.dm.Document.js +++ b/src/dm/ve.dm.Document.js @@ -1276,12 +1276,18 @@ for ( i = 0, l = lines.length; i < l; i++ ) { while ( lines[i] && ( match = query.exec( lines[i] ) ) !== null ) { // Skip empty string matches (e.g. with .*) - if ( query.lastIndex === match.index ) { - // Increment to avoid infinite loop - query.lastIndex++; + if ( match[0].length === 0 ) { + // Set lastIndex to the next character to avoid an infinite + // loop. Browsers differ in whether they do this for you + // for empty matches; see + // http://blog.stevenlevithan.com/archives/exec-bugs + query.lastIndex = match.index + 1; continue; } - ranges.push( new ve.Range( offset + match.index, offset + query.lastIndex ) ); + ranges.push( new ve.Range( + offset + match.index, + offset + match.index + match[0].length + ) ); if ( !noOverlaps ) { query.lastIndex = match.index + 1; } -- To view, visit https://gerrit.wikimedia.org/r/216061 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I87ee908021a95c9b1d08f463c2606dc90dbf8f1f Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Divec <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
