Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/views/application-detail/overview/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const chatBasePath = CHAT_API_BASE_PATH.replace(/\/api$/, '')

const apiDocUrl = new URL(`${CHAT_API_BASE_PATH}-doc/`, window.location.origin).href
const apiQuery=computed(()=>{
const query=application.value?.work_flow?.nodes?.find(n=>n.id==='base-node')?.properties?.api_input_field_list.map((f:any)=>{
const query=application.value?.work_flow?.nodes?.find(n=>n.id==='base-node')?.properties?.api_input_field_list?.map((f:any)=>{
return `${f.variable}=${f.default_value}`
}).join('&')
if(query){

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is a good defensive fix, but it is only partially robust.

What the patch improves

Adding ?. before .map(...) prevents a crash when api_input_field_list is null or undefined.

Because optional chaining short-circuits the rest of the chain, this expression:

api_input_field_list?.map(...).join('&')

will return undefined instead of throwing when api_input_field_list is nullish.

Potential issues

  1. Non-array values still crash
    If api_input_field_list is a non-nullish non-array value, e.g. an object, then ?.map does not protect you because map is not a function:

    api_input_field_list?.map(...) // TypeError if map is undefined

    Use Array.isArray(...) or ensure the API type guarantees an array.

  2. No URL encoding
    Variables and default values are inserted directly:

    `${f.variable}=${f.default_value}`

    If either contains &, =, spaces, #, etc., the query string can break. Use URLSearchParams or encodeURIComponent.

  3. Implicit string conversion
    If default_value is an object, array, null, or undefined, template literals produce values like [object Object], "null", or "undefined". Decide the expected serialization explicitly.

  4. any type
    f: any hides type errors. Prefer a proper type for API input fields.

  5. Minor: find callback assumes every node is non-null
    If nodes can contain nullish entries, n.id can throw. Use n?.id === 'base-node' if necessary.

  6. Computed result type
    The computed value can be undefined when the field list is missing. If it is later interpolated into a URL, ensure a fallback such as ?? ''.

Suggested safer implementation

const query = computed(() => {
  const fields = application.value?.work_flow?.nodes
    ?.find(n => n?.id === 'base-node')
    ?.properties?.api_input_field_list

  if (!Array.isArray(fields)) return ''

  const params = new URLSearchParams()

  fields.forEach((f: any) => {
    if (f?.variable == null) return
    params.append(f.variable, String(f.default_value ?? ''))
  })

  return params.toString()
})

This version:

  • Safely handles missing fields
  • Guarantees a string result
  • Properly URL-encodes values
  • Avoids .map(...).join(...) on a possibly non-array value

Verdict

The diff fixes the obvious nullish crash, but for production code I would still add array validation and URL encoding.

Expand Down
Loading