tui: guard path formatting inputs (#30469)

Fixes #27726, #25216, #24856, #24294, #17071, #29164, #24837, #16865, #14279, #29895
This commit is contained in:
Simon Klee 2026-06-05 11:45:03 +02:00 committed by GitHub
parent c613c33787
commit b278e49e96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 6 deletions

View File

@ -24,7 +24,7 @@ export function usePathFormatter() {
}
function formatPath(input: string | undefined, base: string | undefined) {
if (!input) return ""
if (typeof input !== "string" || !input) return ""
const root = base || process.cwd()
const absolute = path.isAbsolute(input) ? input : path.resolve(root, input)

View File

@ -2534,7 +2534,7 @@ function Skill(props: ToolProps<typeof SkillTool>) {
function Diagnostics(props: { diagnostics?: Record<string, Record<string, any>[]>; filePath: string }) {
const { theme } = useTheme()
const errors = createMemo(() => {
const normalized = Filesystem.normalizePath(props.filePath)
const normalized = Filesystem.normalizePath(typeof props.filePath === "string" ? props.filePath : "")
const arr = props.diagnostics?.[normalized] ?? []
return arr.filter((x) => x.severity === 1).slice(0, 3)
})
@ -2564,7 +2564,7 @@ function input(input: Record<string, any>, omit?: string[]): string {
}
function filetype(input?: string) {
if (!input) return "none"
if (typeof input !== "string" || !input) return "none"
const ext = path.extname(input)
const language = LANGUAGE_EXTENSIONS[ext]
if (["typescriptreact", "javascriptreact", "javascript"].includes(language)) return "typescript"

View File

@ -21,7 +21,7 @@ import { usePathFormatter } from "../../context/path-format"
type PermissionStage = "permission" | "always" | "reject"
function filetype(input?: string) {
if (!input) return "none"
if (typeof input !== "string" || !input) return "none"
const ext = path.extname(input)
const language = LANGUAGE_EXTENSIONS[ext]
if (["typescriptreact", "javascriptreact", "javascript"].includes(language)) return "typescript"
@ -35,8 +35,14 @@ function EditBody(props: { request: PermissionRequest }) {
const config = useTuiConfig()
const dimensions = useTerminalDimensions()
const filepath = createMemo(() => (props.request.metadata?.filepath as string) ?? "")
const diff = createMemo(() => (props.request.metadata?.diff as string) ?? "")
const filepath = createMemo(() => {
const value = props.request.metadata?.filepath
return typeof value === "string" ? value : ""
})
const diff = createMemo(() => {
const value = props.request.metadata?.diff
return typeof value === "string" ? value : ""
})
const view = createMemo(() => {
const diffStyle = config.diff_style