Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Clarify the documentation of pathlib.Path.is_relative_to() #99334

Closed
Labels
@thomas-mckay

Description

@thomas-mckay

Hi,

Currently (python 3.10.6 & 3.11.0):

frompathlibimportPathp=Path('/var/log/../../opt')p.is_relative_to('/var/log')>>>Truep=p.resolve()p.is_relative_to('/var/log')>>>False

Once you knowis_relative_to usesrelative_to, this makes more sense but it's not obvious from the documentation and the examples given. Also it can easily lead to code that looks secure but isn't. Case in point, I was tasked with reviewing this code today (simplified for illustration purposes):

path=Path(ROOT_PATH,user_input_rel_path)ifpath.is_relative_to(ROOT_PATH):path.unlink()else:raisePermissionError('Nope!')

I was unsure if I should open a bug or not because one could easily argue it isn't a bug. I do believe however that a warning in the documentation could save a few devs from making a mistake.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp