Skip to content

fix: correctly detect if a path is inside the project root or not#701

Open
jfly wants to merge 1 commit into
numtide:mainfrom
jfly:issue-700
Open

fix: correctly detect if a path is inside the project root or not#701
jfly wants to merge 1 commit into
numtide:mainfrom
jfly:issue-700

Conversation

@jfly
Copy link
Copy Markdown
Collaborator

@jfly jfly commented May 27, 2026

We had a handful of bugs here:

  1. It's not enough to check if a relative path starts with .., as it's valid for files to literally start with 2 dots. You need to check for the path separator as well.
  2. Stdin mode incorrectly assumed that any paths that start with .. are outside of the tree root. This is wrong in 2 ways: - If we're in a subdirectory of the project, ../foo is still very much inside the project. - Path's can still escape without starting with ../. For example: foo/../../bar escapes the project root.
  3. Stdin mode incorrectly treated relative paths given by the user as relative to the project root. Now they are correctly treated as relative the current directory, and massaged into paths that are relative to the project root. The simplest approach to fixing this was to DRY up the path processing logic between stdin/non stdin mode.

This fixes #700

We had a handful of bugs here:

1. It's not enough to check if a relative path starts with `..`, as it's
   valid for files to literally start with 2 dots. You need to check for
   the path separator as well.
2. Stdin mode incorrectly assumed that any paths that start with `..`
   are outside of the tree root. This is wrong in 2 ways:
     - If we're in a subdirectory of the project, `../foo` is still very much inside the
       project.
     - Path's can still escape without starting with `../`. For example:
       `foo/../../bar` escapes the project root.
3. Stdin mode incorrectly treated relative paths given by the user as
   relative to the project root. Now they are correctly treated as
   relative the current directory, and massaged into paths that are
   relative to the project root. The simplest approach to fixing this
   was to DRY up the path processing logic between stdin/non stdin mode.

This fixes numtide#700
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.

Files starting with .. treated as outside tree root

1 participant