Skip to content

Commit fde6f81

Browse files
committed
fix(core): guard material-ref parsers against non-string values (Sentry 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).
1 parent 5e5b62b commit fde6f81

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

packages/core/src/material-library.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,13 +4187,14 @@ export function toSceneMaterialRef(id: string) {
41874187
}
41884188

41894189
export function getLibraryMaterialIdFromRef(materialRef?: string | null) {
4190-
if (!materialRef) return null
4190+
if (typeof materialRef !== 'string') return null
41914191
if (!materialRef.startsWith(LIBRARY_MATERIAL_REF_PREFIX)) return null
41924192
return materialRef.slice(LIBRARY_MATERIAL_REF_PREFIX.length)
41934193
}
41944194

41954195
export function getSceneMaterialIdFromRef(materialRef?: string | null): string | null {
4196-
if (!materialRef?.startsWith(SCENE_MATERIAL_REF_PREFIX)) return null
4196+
if (typeof materialRef !== 'string') return null
4197+
if (!materialRef.startsWith(SCENE_MATERIAL_REF_PREFIX)) return null
41974198
return materialRef.slice(SCENE_MATERIAL_REF_PREFIX.length)
41984199
}
41994200

0 commit comments

Comments
 (0)