Add safe_join for safely building filesystem paths.
Review Request #13166 — Created July 31, 2023 and submitted
djblets.util.filesystem.safe_join(), a port and
modernization of Django's internal
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 (
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.