Add safe_join for safely building filesystem paths.

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

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.

Commits

Files