fix(util): read a path's folder and extension from its name - #835
Open
ANIRUDDHA ADAK (aniruddhaadak80) wants to merge 1 commit into
Open
ANIRUDDHA ADAK (aniruddhaadak80) wants to merge 1 commit into
ANIRUDDHA ADAK (aniruddhaadak80) wants to merge 1 commit into
Conversation
ANIRUDDHA ADAK (aniruddhaadak80)
requested review from
Aayam Bansal (aayambansal) and
Ishaan Gangwani (ishaan1124)
as code owners
September 29, 2026 17:50
|
ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel. A member of the Team first needs to authorize it. |
ANIRUDDHA ADAK (aniruddhaadak80)
force-pushed
the
fix/path-bare-directory
branch
2 times, most recently
from
September 30, 2026 09:49
c29a906 to
898cf98
Compare
getDirectory joined an empty slice to a slash, so a bare filename reported the filesystem root. getFileExtension split the whole path on a dot, so an extensionless name returned itself and a dotfile returned its name minus the dot. Both now work off the filename, and a leading dot is not an extension.
ANIRUDDHA ADAK (aniruddhaadak80)
force-pushed
the
fix/path-bare-directory
branch
from
September 30, 2026 10:16
898cf98 to
547e5db
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two helpers in
tooling/util/src/path.tswork on the whole path where they should work on the filename:Why it matters
A bare filename is reported as living in the filesystem root.
getDirectory("foo")splits to["foo"], the slice is[], and[].join("/") + "/"is"/":A file with no extension gets its own name as the extension, and a dotfile gets its name minus the dot, and a dot in a directory leaks through:
This isn't a matter of taste —
getFilenameTruncated, four lines below in the same file, already implements the correct rule for the same question (const ext = lastDot <= 0 ? "" : ...). The module contradicted itself.It's UI-visible:
session-turn.tsx:1258renders`${getDirectory(diff.file)}`directly, so a root-level filename displays/as its directory, and any caller branching on extension misroutes extensionless and dotfile paths.Verification
Neither helper had a test. New
test/util/path-helpers.test.ts, three cases failing before:After:
The
getDirectory("/")case is pinned explicitly: trimming a lone/leaves"", and that is still the root, so the new guard returns/rather than"". The wholetest/util/suite is 59 pass / 0 fail.The change
export function getDirectory(path: string | undefined) { if (!path) return "" const trimmed = path.replace(/[\/\\]+$/, "") + // A lone "/" trims away entirely, but it is still the root. + if (trimmed === "") return "/" const parts = trimmed.split(/[\/\\]/) + // A bare filename has no parent, and an empty slice joined to "/" would + // report the filesystem root instead. + if (parts.length <= 1) return "" return parts.slice(0, parts.length - 1).join("/") + "/" } export function getFileExtension(path: string | undefined) { if (!path) return "" - const parts = path.split(".") - return parts[parts.length - 1] + // Only the filename carries an extension: a dot in a directory name, or in + // an earlier path segment, is not one. + const base = getFilename(path) + const dot = base.lastIndexOf(".") + // A leading dot marks a dotfile, not an extension, and no dot means none. + if (dot <= 0) return "" + return base.slice(dot + 1) }getFileExtensionnow reusesgetFilenamefrom the same module, which already strips both separators.Touched files are Prettier-clean (verified on LF-normalized copies; this Windows checkout's
core.autocrlf=truemakes Prettier flag every file repo-wide).Fixes #834