Skip to content

Commit

Permalink
Add interpolate argument to avoid resolving proxied values.
Browse files Browse the repository at this point in the history
The argument is already documented but not implemented yet.
Fixes #415
  • Loading branch information
David-Wobrock committed Sep 5, 2023
1 parent fe59a81 commit 4b4d6a8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is inspired by `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

`v0.x.y`_ - Unreleased
-------------------------------
Added
+++++
- Added support for ``interpolate`` parameter
`#415 <https://github.com/joke2k/django-environ/pull/415>`_.

`v0.11.2`_ - 1-September-2023
-------------------------------
Fixed
Expand Down
2 changes: 1 addition & 1 deletion docs/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Proxy value
===========

Values that being with a ``$`` may be interpolated. Pass ``interpolate=True`` to
``environ.Env()`` to enable this feature:
``environ.Env()`` to enable this feature (``True`` by default):

.. code-block:: python
Expand Down
6 changes: 4 additions & 2 deletions environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ class Env:
for s in ('', 's')]
CLOUDSQL = 'cloudsql'

def __init__(self, **scheme):
def __init__(self, interpolate=True, **scheme):
self.smart_cast = True
self.escape_proxy = False
self.prefix = ""
self.interpolate = interpolate
self.scheme = scheme

def __call__(self, var, cast=None, default=NOTSET, parse_default=False):
Expand Down Expand Up @@ -396,7 +397,8 @@ def get_value(self, var, cast=None, default=NOTSET, parse_default=False):
# Resolve any proxied values
prefix = b'$' if isinstance(value, bytes) else '$'
escape = rb'\$' if isinstance(value, bytes) else r'\$'
if hasattr(value, 'startswith') and value.startswith(prefix):
if self.interpolate and \
hasattr(value, 'startswith') and value.startswith(prefix):
value = value.lstrip(prefix)
value = self.get_value(value, cast=cast, default=default)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ def test_bool_true(self, value, variable):
def test_proxied_value(self):
assert self.env('PROXIED_VAR') == 'bar'

def test_not_interpolated_proxied_value(self):
env = Env(interpolate=False)
assert env('PROXIED_VAR') == '$STR_VAR'

def test_dollar_sign(self):
assert self.env('DOLLAR_VAR') == 'SOME_VALUE$S3CR3TK3Y@HELLO'

Expand Down

0 comments on commit 4b4d6a8

Please sign in to comment.