Skip to content

fix(prompts): handle trailing backslash in path prompt directory mode - #627

Merged
43081j merged 2 commits into
bombshell-dev:mainfrom
b84330808:fix/path-prompt-windows-separator
Oct 28, 2026
Merged

43081j merged 2 commits into
bombshell-dev:mainfrom
b84330808:fix/path-prompt-windows-separator

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

What does this PR do?

On Windows, the path prompt with directory: true can't descend into a directory with the native separator. Typing C:\project\ shows "No matches found", and Enter just reports "Please select a path". The same happens when initialValue ends in \.

The directory-mode check only looked for a trailing /, so a trailing \ fell through to dirname(). The prompt then listed the siblings of C:\project, filtered by C:\project\, which matched nothing. This PR treats a trailing path.sep the same as /. On POSIX nothing changes, since sep is /.

There's no issue for this; I found it while running the path prompt tests on Windows 11, and the fix is small enough to discuss here.

The new test mocks node:path with path.win32 and maps C:\… paths onto memfs, so it also runs on Linux CI. It fails on main (both cases return the cancel symbol) and passes with this change.

Typing / on Windows still doesn't match, because join() rewrites the suggestions to \. I left that for a separate change.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

I used Claude Code to write this change.

On Windows the native separator is `\`, but the directory-mode check only
looked for a trailing `/`. Typing `C:\project\` with `directory: true`
listed the siblings of `C:\project` filtered by `C:\project\`, so the
prompt showed no matches and Enter could not submit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: abe678d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clack/prompts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@b84330808

Copy link
Copy Markdown
Contributor Author

The detect job fails at npm install --prefix automation (Cannot read properties of null (reading 'edgesOut')), same as on #628 and #624, so it looks unrelated to this change. Mind taking a look when you get a chance?

Comment thread packages/prompts/src/path.ts Outdated
Per review: treat a trailing "/" or "\" as a separator regardless of
platform, and move the Windows cases into path.test.ts behind skipIf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Oct 28, 2026

Copy link
Copy Markdown

commit: abe678d

@43081j
43081j merged commit 34976a7 into bombshell-dev:main Oct 28, 2026
9 checks passed
@bombshell-bot bombshell-bot Bot mentioned this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants