From 9d3c04878521ea4cab1d283a4a4c68978d7f2472 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Mon, 3 Apr 2023 12:51:41 -0500 Subject: [PATCH] EditCheck: catch errors from TransactionSquasher Bug: T324733 Change-Id: I5076db530fa8af72a336916f8284e6f3348cfd38 --- modules/editcheck/init.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/editcheck/init.js b/modules/editcheck/init.js index 4cf5bad785..c70717a51e 100644 --- a/modules/editcheck/init.js +++ b/modules/editcheck/init.js @@ -7,16 +7,22 @@ mw.editcheck.doesAddedContentNeedReference = function ( documentModel ) { var ranges = []; var offset = 0; var endOffset = documentModel.getDocumentRange().end; - documentModel.completeHistory.squash().transactions[ 0 ].operations.every( function ( op ) { - if ( op.type === 'retain' ) { - offset += op.length; - } else if ( op.type === 'replace' ) { - ranges.push( new ve.Range( offset, offset + op.insert.length ) ); - offset += op.insert.length; - } - // Reached the end of the doc / start of internal list, stop searching - return offset < endOffset; - } ); + try { + documentModel.completeHistory.squash().transactions[ 0 ].operations.every( function ( op ) { + if ( op.type === 'retain' ) { + offset += op.length; + } else if ( op.type === 'replace' ) { + ranges.push( new ve.Range( offset, offset + op.insert.length ) ); + offset += op.insert.length; + } + // Reached the end of the doc / start of internal list, stop searching + return offset < endOffset; + } ); + } catch ( e ) { + // TransactionSquasher can sometimes throw errors; until T333710 is + // fixed just count this as not needing a reference. + return false; + } return ranges.some( function ( range ) { var minimumCharacters = 50; // 1. Check that at least minimumCharacters characters have been inserted sequentially