admin/internet: faulty "home/root" field with bad number of slashes

Massimo Melina committed Mar 9, 2026 at 20:36 UTC e254e1505b09877e78cc0ca3d9669fbeffa8e83f
1 file changed +6 -4
admin/src/VfsPathField.ts
+6 -4
@@ -1,4 +1,5 @@
1 -import { dirname, enforceFinal } from './misc'
1 +import { dirname, enforceFinal, join } from './misc'
2 +import _ from 'lodash'
3 import { useApiList } from './api'
4 import { createElement as h, useMemo } from 'react'
5 import { Autocomplete, AutocompleteProps, TextField } from '@mui/material'
@@ -9,7 +10,7 @@ interface VfsPathFieldProps extends FieldProps<string> {
10 }
11
12 export default function VfsPathField({ value='', onChange, helperText, setApi, autocompleteProps, folders=true, files=true, ...props }: VfsPathFieldProps) {
12 - const uri = dirname(value)
13 + const uri = dirname(value.replace(/\/{2,}/g, '/'))
14 const { list, loading } = useApiList('get_file_list', {
15 uri,
16 admin: true,
@@ -17,8 +18,9 @@ export default function VfsPathField({ value='', onChange, helperText, setApi, a
18 onlyFolders: !files
19 })
20 const options = useMemo(() => {
20 - const ret = [uri && (dirname(uri) + '/'), uri + '/'].filter(Boolean).concat(list.map(x => uri + '/' + x.n))
21 - if (value && !ret.includes(value)) ret.push(value) // console warning otherwise
21 + const ret = _.uniq([uri && (dirname(uri) + '/'), enforceFinal('/', uri)].filter(Boolean))
22 + .concat(list.map(x => join(uri, x.n)))
23 + if (value && !ret.includes(value)) ret.push(value) // allow re-selection of the same value without issuing a console warning
24 return ret
25 }, [list, uri])
26 setApi?.({