Add safe_join for safely building filesystem paths.

Review Request #13166 — Created July 31, 2023 and submitted

Information

Djblets
release-4.x

Reviewers

This introduces djblets.util.filesystem.safe_join(), a port and
modernization of Django's internal django.utils._os.safe_join(). This
will join a series of paths and validate the result, making sure that
the resulting path is confined to the base path.

Our version also allows the result to be returned as a relative path,
and to use a specific pathing module (ntpath or posixpath). It also
provides type hints.

The main benefit is to avoid relying on an internal function that Django
may remove or substantially change at any time.

Unit tests pass.

Used this in some in-progress code.

Summary ID
Add safe_join for safely building filesystem paths.
This introduces `djblets.util.filesystem.safe_join()`, a port and modernization of Django's internal `django.utils._os.safe_join()`. This will join a series of paths and validate the result, making sure that the resulting path is confined to the base path. Our version also allows the result to be returned as a relative path, and to use a specific pathing module (`ntpath` or `posixpath`). It also provides type hints. The main benefit is to avoid relying on an internal function that Django may remove or substantially change at any time.
f22ba6c57e4d209780dd2fbd5fd215b79c984d77
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-4.x (63d15c9)
Loading...