From 5f888c98fac9f92fccab793dc76d7f27ed820428 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Tue, 3 Sep 2024 13:37:31 +0200 Subject: [PATCH] Finish safety fallback for missing groups In a document without references, the default group doesn't exist. Make sure that we don't assume any group's existence. Bug: T373661 Change-Id: I1bfd41b0b61938f32219d61142cd576c8ca97ace --- modules/ve-cite/ve.dm.MWGroupReferences.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/ve-cite/ve.dm.MWGroupReferences.js b/modules/ve-cite/ve.dm.MWGroupReferences.js index d40519b28..f07f425ff 100644 --- a/modules/ve-cite/ve.dm.MWGroupReferences.js +++ b/modules/ve-cite/ve.dm.MWGroupReferences.js @@ -44,7 +44,12 @@ ve.dm.MWGroupReferences = function VeDmMWGroupReferences() { /** @private */ this.topLevelCounter = 1; - /** @private */ + /** + * InternalList node group, or null if no such group exists. + * + * @member {Object|null} + * @private + */ this.nodeGroup = null; }; @@ -166,7 +171,7 @@ ve.dm.MWGroupReferences.prototype.getTopLevelKeysInReflistOrder = function () { * @return {ve.dm.MWReferenceNode|undefined} */ ve.dm.MWGroupReferences.prototype.getRefNode = function ( key ) { - const keyedNodes = this.nodeGroup.keyedNodes[ key ]; + const keyedNodes = this.nodeGroup && this.nodeGroup.keyedNodes[ key ]; return keyedNodes && keyedNodes[ 0 ]; }; @@ -195,7 +200,6 @@ ve.dm.MWGroupReferences.prototype.getInternalModelNode = function ( key ) { * @return {ve.dm.MWReferenceNode[]} */ ve.dm.MWGroupReferences.prototype.getRefUsages = function ( key ) { - // T373661: This might never have been set in source mode return ( this.nodeGroup && this.nodeGroup.keyedNodes[ key ] || [] ) .filter( ( node ) => !node.getAttribute( 'placeholder' ) && !node.findParent( ve.dm.MWReferencesListNode )