mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-04 20:50:06 +00:00
fix: add defensive guard for invalid modelType in findProvidersWithFallback
- Early return undefined for null/undefined/non-string inputs - Prevents potential runtime errors from .split() on invalid types - Add tests for invalid input handling Amp-Thread-ID: https://ampcode.com/threads/T-019c0849-5650-7060-b4bd-23ef0c8dfa39 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -539,5 +539,16 @@ describe('useModelToNodeStore', () => {
|
||||
expect(modelToNodeStore.getNodeProvider('')).toBeUndefined()
|
||||
expect(modelToNodeStore.getAllNodeProviders('')).toEqual([])
|
||||
})
|
||||
|
||||
it('should handle invalid input types gracefully', () => {
|
||||
const modelToNodeStore = useModelToNodeStore()
|
||||
modelToNodeStore.registerDefaults()
|
||||
|
||||
expect(modelToNodeStore.getNodeProvider(null as any)).toBeUndefined()
|
||||
expect(modelToNodeStore.getNodeProvider(undefined as any)).toBeUndefined()
|
||||
expect(modelToNodeStore.getNodeProvider(123 as any)).toBeUndefined()
|
||||
expect(modelToNodeStore.getAllNodeProviders(null as any)).toEqual([])
|
||||
expect(modelToNodeStore.getAllNodeProviders(undefined as any)).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -81,6 +81,10 @@ export const useModelToNodeStore = defineStore('modelToNode', () => {
|
||||
function findProvidersWithFallback(
|
||||
modelType: string
|
||||
): ModelNodeProvider[] | undefined {
|
||||
if (!modelType || typeof modelType !== 'string') {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const exactMatch = modelToNodeMap.value[modelType]
|
||||
if (exactMatch && exactMatch.length > 0) return exactMatch
|
||||
|
||||
|
||||
Reference in New Issue
Block a user