diff --git a/website/docs/frontend-conventions.md b/website/docs/frontend-conventions.md index 4b5ba994579a..708f28f418ed 100644 --- a/website/docs/frontend-conventions.md +++ b/website/docs/frontend-conventions.md @@ -428,6 +428,13 @@ payloads. Widening that regex or its key scope is a security change — the same constant also decides which paths are treated as local file reads, so the two decisions must stay on the one exported copy in `urlTransform.ts`. +To SHOW a gateway path's file name, use `pathBasename` (and +`stripTrailingSeparators` for a directory) from `utils/pathBasename.ts`, never +`.split('/').pop()`: a Windows gateway reports `C:\repo\a.ts`, which a `/`-only +split shows whole. The helper treats `\` as a separator only in a drive-rooted +or backslash-UNC path, because on POSIX a backslash is a legal file-name +character. It is display-only and decides nothing about which paths may be read. + ## Data fetching The shared memory editor keeps the existing global V1 Key/Value/Set action diff --git a/website/src/apps/file-explorer/PathBar.tsx b/website/src/apps/file-explorer/PathBar.tsx index 2939a765d913..d4b96ead762e 100644 --- a/website/src/apps/file-explorer/PathBar.tsx +++ b/website/src/apps/file-explorer/PathBar.tsx @@ -3,7 +3,7 @@ import { useQuery } from '@tanstack/react-query' import { FolderTree, Folder, File, GitBranch } from 'lucide-react' import Clickable from '../../components/Clickable' import { fileExplorerApi } from './api' -import { basename, parentChain } from './utils' +import { crumbLabel, parentChain } from './utils' import { useDebouncedValue } from './hooks' import type { GitInfo, TreeEntry } from './types' @@ -121,7 +121,7 @@ export default function PathBar({ rootPath, gitInfo, onChangeRoot, onNavigate }: {i > 0 && /} { e.stopPropagation(); onChangeRoot(s) }} role="button" tabIndex={0} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.stopPropagation(); onChangeRoot(s) } }}> - {i === 0 ? '/' : basename(s) || s} + {i === 0 ? '/' : crumbLabel(s) || s} ))} diff --git a/website/src/apps/file-explorer/utils.ts b/website/src/apps/file-explorer/utils.ts index b98f31a73e69..4c921d8324b4 100644 --- a/website/src/apps/file-explorer/utils.ts +++ b/website/src/apps/file-explorer/utils.ts @@ -2,6 +2,7 @@ import { safeSetItem } from '../../utils/safeStorage' import { STORAGE_KEY } from './constants' import { fmtBytes, fmtDateTimeNumeric } from '../../i18n/format' import { hasCommandModifier } from '../../utils/commandModifier' +import { pathBasename, stripTrailingSeparators } from '../../utils/pathBasename' export const extOf = (p: string) => { const slash = Math.max(p.lastIndexOf('/'), p.lastIndexOf('\\')) @@ -11,11 +12,7 @@ export const extOf = (p: string) => { return base.slice(i).toLowerCase() } -export const basename = (p: string) => { - const s = p.replace(/\/+$/, '') - const i = s.lastIndexOf('/') - return i < 0 ? s : s.slice(i + 1) -} +export const basename = (p: string) => pathBasename(stripTrailingSeparators(p)) export const dirname = (p: string) => { const s = p.replace(/\/+$/, '') @@ -24,6 +21,12 @@ export const dirname = (p: string) => { return s.slice(0, i) } +/** Label for one `parentChain` crumb. The chain is built by splitting on `/` + * only, so its label splits on `/` only too: a Windows root stays one crumb + * showing the whole path, exactly as before #14581. Breadcrumb navigation for + * Windows roots is a separate change. */ +export const crumbLabel = (p: string) => p.replace(/\/+$/, '').split('/').at(-1) ?? '' + export const parentChain = (p: string) => { const out: string[] = [] let cur = p.replace(/\/+$/, '') diff --git a/website/src/components/DiffBlock.tsx b/website/src/components/DiffBlock.tsx index 20e332469809..46b1fc2eaf10 100644 --- a/website/src/components/DiffBlock.tsx +++ b/website/src/components/DiffBlock.tsx @@ -13,6 +13,7 @@ import { usePlainDiff } from '../hooks/usePlainDiff' import { i18nT } from '../i18n/t' import { useLanguageGeneration } from '../i18n/useLanguageGeneration' +import { pathBasename } from '../utils/pathBasename' /** Extract the target file path from unified-diff header lines. * @@ -93,7 +94,7 @@ export function extractFilePath(code: string): { path: string; prefixStripped: b * path, making "relative spelling absent" meaningless as evidence. */ const ROOTLESS_ABS_RE = /^(home|Users|tmp|var|opt|workplace)\// -const basename = (path: string) => path.slice(path.lastIndexOf('/') + 1) +const basename = pathBasename /** What a file's header row is titled: the basename, and for a rename the old * basename, an arrow, the new one. The full path is the wrapper's tooltip and diff --git a/website/src/components/FileRenderers.tsx b/website/src/components/FileRenderers.tsx index d5ae6b246697..41e3a2868ce2 100644 --- a/website/src/components/FileRenderers.tsx +++ b/website/src/components/FileRenderers.tsx @@ -10,6 +10,7 @@ import { useCanOpenFile, useCopyAck } from './FilePathMenu' import { fileDownloadUrl, fileStreamUrl, fileOfficePreviewUrl, fileOfficeSlidesUrl, fileOfficeSlideUrl } from '../utils/fileReadUrl' import { sendErrorToChat } from '../utils/errorReport' import { useLanguageGeneration } from '../i18n/useLanguageGeneration' +import { pathBasename } from '../utils/pathBasename' /* ── extension helpers ── */ const IMG_EXTS = new Set(['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp', '.avif', '.svg', '.ico']) const CSV_EXTS = new Set(['.csv', '.tsv']) @@ -78,7 +79,7 @@ export const ImageViewer = memo(function ImageViewer({ filePath }: { filePath: s