Fix crash when resource.link is undefined in match processing#155
Open
mherman22 wants to merge 1 commit into
Open
Fix crash when resource.link is undefined in match processing#155mherman22 wants to merge 1 commit into
mherman22 wants to merge 1 commit into
Conversation
Patient resources may not have a link array when they are first submitted or when they have been unlinked. Four locations in matchMixin.js called .find() on resource.link without checking if it exists, causing TypeError: Cannot read properties of undefined (reading 'find'). Add null checks before .find() on: - entry.resource.link (line 748) — golden record reuse check - auto.resource.link (line 592) — auto match current link check - potential.resource.link (line 626) — potential match check - conflict.resource.link (line 685) — conflict match check The addLinks function (lines 515, 530) is safe because it initializes link to [] on lines 512-513 and 527-528. Line 928 already had the correct guard pattern. Fixes intrahealth#153
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The app crashes with
TypeError: Cannot read properties of undefined (reading 'find')when a Patient resource has nolinkarray during match processing.This happens because
resource.linkcan beundefinedwhen a patient is first submitted, has been unlinked, or when the FHIR store returns a resource without links.Fix
Add
resource.link &&guard before.find()at four locations inmatchMixin.js:entry.resource.link.find(...)entry.resource.link && entry.resource.link.find(...)auto.resource.link.find(...)auto.resource.link && auto.resource.link.find(...)potential.resource.link.find(...)potential.resource.link && potential.resource.link.find(...)conflict.resource.link.find(...)conflict.resource.link && conflict.resource.link.find(...)This matches the pattern already used at line 928 (
currentLink.resource.link && currentLink.resource.link.find(...)) which was the only guarded call.The
addLinksfunction (lines 515, 530) is safe because lines 512-513 and 527-528 already initializelinkto[]if missing.Fixes #153