diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ef00d40a..e940019b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,11 @@ and this project adheres to `Semantic Versioning `_. + Changed +++++++ - Disabled inline comments handling by default due to potential side effects. @@ -15,7 +20,6 @@ Changed `#499 `_. - `v0.11.2`_ - 1-September-2023 ----------------------------- Fixed diff --git a/docs/tips.rst b/docs/tips.rst index 66538c40..f8510ce3 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -291,7 +291,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 diff --git a/environ/environ.py b/environ/environ.py index a3d64f2d..dba6116e 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -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): @@ -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) diff --git a/tests/test_env.py b/tests/test_env.py index 681458ea..099931f1 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -186,6 +186,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'