fix(core): guard material-ref parsers against non-string values (Sentry MONOREPO-EDITOR-EM)#486
Open
anton-pascal wants to merge 1 commit into
Open
fix(core): guard material-ref parsers against non-string values (Sentry MONOREPO-EDITOR-EM)#486anton-pascal wants to merge 1 commit into
anton-pascal wants to merge 1 commit into
Conversation
…ry MONOREPO-EDITOR-EM) getLibraryMaterialIdFromRef and getSceneMaterialIdFromRef only guarded against null/undefined, then called .startsWith(). When a non-string material ref reaches them (legacy/malformed wall material slot ref), .startsWith is undefined -> TypeError: e.startsWith is not a function. Narrow with typeof !== 'string' -> return null, so a bad ref degrades to 'no library/scene material' instead of throwing during wall material resolution (packages/viewer wall-materials.ts -> parseMaterialRef).
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.
What
Add a
typeof materialRef !== 'string'guard togetLibraryMaterialIdFromRefandgetSceneMaterialIdFromRefinpackages/core/src/material-library.ts.Why
Both functions only guarded against null/undefined before calling
.startsWith():When a non-string material ref reaches them (a legacy or malformed wall material slot ref),
.startsWithis undefined ->TypeError: e.startsWith is not a function.Stack originates in wall material resolution:
packages/viewer/src/systems/wall/wall-materials.ts->parseMaterialRef(ref)->getLibraryMaterialIdFromRef.Safety
typeof x !== 'string'narrows tostring, so.startsWith/.sliceremain valid; return type unchanged (non-string already mapped tonull). Behaviour for real string refs is identical.Verification
tsc --noEmiton @pascal-app/core: exit 0. biome check: clean.Opened by nightly Sentry triage. Do not auto-merge - review first.
Note
Low Risk
Narrow defensive change in core parsing; string refs unchanged, non-strings now return null instead of throwing.
Overview
Hardens
getLibraryMaterialIdFromRefandgetSceneMaterialIdFromRefinmaterial-library.tsso they returnnullwhen the input is not a string, instead of calling.startsWithon numbers or other legacy/malformed wall slot values.getSceneMaterialIdFromRefno longer relies on optional chaining alone on.startsWith; it uses the same explicit string check as the library helper. Valid string refs behave the same;parseMaterialRefand downstream wall material resolution getnullinstead of a runtimeTypeError(Sentry MONOREPO-EDITOR-EM).Reviewed by Cursor Bugbot for commit fde6f81. Bugbot is set up for automated code reviews on this repo. Configure here.