Skip to content

fix(import): keep staged category folders inside the temp directory - #68

Merged
erunion merged 4 commits into
mainfrom
erunion/import-staging-containment-092d
Nov 12, 2026
Merged

erunion merged 4 commits into
mainfrom
erunion/import-staging-containment-092d

Conversation

@erunion

@erunion erunion commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Remote category titles from llms.txt, Mintlify groups, and other nav sources were used as the first folder name under the import staging directory. namespaceSubDir only split on / and kept that segment as written. On Windows, path.join treats \ as a separator and collapses .., so a title such as ..\..\..\Users\Public\poc wrote frontmatter stubs and _order.yaml outside the mkdtemp directory. Cleanup only deletes the temp dir, so those files would remain.

stageOrganized now does two things:

  • Rewrites an unsafe first segment to kebab-case. Unsafe means Windows would trim it to empty (., .., and .. all do), or the raw segment contains \, /, :, or a control character. Guides, API Docs, and v2. stay as authored. The rewritten name is cached by the original segment, so SDK: Java/Setup/Windows and SDK: Java/Setup/Linux share sdk-java instead of splitting into sdk-java and sdk-java-2.
  • Runs every stub, index.md, and _order.yaml write through makeContainment, so a path that still resolves outside the staging directory throws PathEscapeError before mkdir.

A regression test stages the hostile titles and re-joins the resulting relative paths with path.win32. Another checks the shared SDK: Java tree. A third checks that ., .., and a .. segment become page folders. A fourth injects a ../ slug and expects PathEscapeError with no file written outside the temp dir.

npx vitest run — 302 passed.

Fixes RM-19530.

Open in Web Open in Cursor 

Remote category titles were used as the first path segment under the
import staging directory. On Windows, path.join treats backslashes as
separators, so a title like ..\..\Users\Public\poc wrote stubs outside
the mkdtemp dir. Rewrite unsafe segments to kebab-case and run every
stageOrganized write through the staging containment check.

Co-authored-by: Jon Ursenbach <erunion@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (3) · Last reviewed commit: "fix(import): reuse a rewritten category ..." · Reviewed by Greptile

Comment thread src/commands/import.js Resolved
SDK: Java/Setup/Windows and SDK: Java/Setup/Linux both kebab the shared
root to sdk-java. Allocating that name on every call split the tree and
reused the child slug under a second parent. Cache the first segment by
its original text, the same way later segments already are.

A safe display title is returned unchanged, so a trailing period is no
longer treated as a rewrite.

Co-authored-by: Jon Ursenbach <erunion@users.noreply.github.com>
greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 12, 2026
Windows trims trailing dots and spaces before the path is used, so
".", "..", and ".. " are already empty by the time safeCategorySegment
looks at them. The "." and ".." comparisons never ran.

Co-authored-by: Jon Ursenbach <erunion@users.noreply.github.com>
@greptile-apps
greptile-apps Bot dismissed their stale review November 12, 2026 21:41

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

Wrap expectContainedOnWin32 in vi.defineHelper so a failed Windows path
assertion is reported on the test line that called it.

Co-authored-by: Jon Ursenbach <erunion@users.noreply.github.com>
@erunion
erunion merged commit bf0d4e2 into main Nov 12, 2026
4 checks passed
@erunion
erunion deleted the erunion/import-staging-containment-092d branch November 12, 2026 21:56
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