From 472323f303966c0aa0eae3c7210a7bfd747bf20e Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Wed, 21 Aug 2024 19:59:46 -0400 Subject: [PATCH] Digital PCT265 defect: Missing moecule.id to moduleName validation for the replacement behavior. --- .../Behaviors/ReplaceableMoleculeBehaviorModel.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift index c35a5d19..3d234065 100644 --- a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift +++ b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift @@ -49,9 +49,15 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Pa public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?, changes: inout [MoleculeModelProtocol]) -> [MoleculeModelProtocol]? { self.delegateObject = delegateObject - let moleculeModels = moleculeIds.compactMap { moleculeId in + let moleculeModels: [MoleculeModelProtocol] = moleculeIds.compactMap { moleculeId in do { - return try delegateObject?.moleculeDelegate?.getModuleWithName(moleculeId) + guard let molecule = try delegateObject?.moleculeDelegate?.getModuleWithName(moleculeId) else { + return nil // Valid. Module might not be present yet. + } + guard molecule.id == moleculeId else { + throw MolecularError.validationError("The module name \(moleculeId) must match the molecule id \(molecule.id) it encloses!") + } + return molecule } catch { let coreError = MVMCoreErrorObject.createErrorObject(for: error, location: String(describing: type(of: self)))! if let error = error as? HumanReadableDecodingErrorProtocol {