Repository: sayanarijit/expandvars

Issue:
Right Hand Side Variable Not Expanded with the '-' Operator
Take the example that I got from some random website

```
VAR1=1
VAR2=2
# var3 is unset.

echo ${VAR1-$VAR2}   # 1
echo ${VAR3-$VAR2}   # 2
```

This seems to be normal bash behaviour, but in the above example expandvars will output `1` and `$VAR2` respectively. Here is the Python code

```python

import os
from expandvars import expandvars

os.environ['VAR1'] = '1'
os.environ['VAR2'] = '2'

v = '${VAR1-$VAR2}'
print(f'{v} expands to "{expandvars(v)}"')    # ${VAR1-$VAR2} expands to "1"

v = '${VAR3-$VAR2}'
print(f'{v} expands to "{expandvars(v)}"')    # ${VAR3-$VAR2} expands to "$VAR2"
```

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/sayanarijit/expandvars/pull/41?src=pr&el=h1) Report
> Merging [#41](https://codecov.io/gh/sayanarijit/expandvars/pull/41?src=pr&el=desc) (3974933) into [master](https://codecov.io/gh/sayanarijit/expandvars/commit/128143fb31af000679e71d7cee876b71879fe664?el=desc) (128143f) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/sayanarijit/expandvars/pull/41/graphs/tree.svg?width=650&height=150&src=pr&token=LaBTTAtjk0)](https://codecov.io/gh/sayanarijit/expandvars/pull/41?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##            master       #41   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          465       465           
=========================================
  Hits           465       465           
```


| [Impacted Files](https://codecov.io/gh/sayanarijit/expandvars/pull/41?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [expandvars.py](https://codecov.io/gh/sayanarijit/expandvars/pull/41/diff?src=pr&el=tree#diff-ZXhwYW5kdmFycy5weQ==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/sayanarijit/expandvars/pull/41?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/sayanarijit/expandvars/pull/41?src=pr&el=footer). Last update [128143f...3974933](https://codecov.io/gh/sayanarijit/expandvars/pull/41?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

sayanarijit: https://github.com/sayanarijit/expandvars/blob/128143fb31af000679e71d7cee876b71879fe664/tests/test_expandvars.py#L66

Hey thanks... Please add a test case below this.
sayanarijit: ```
git clone https://github.com/Anti-Distinctlyminty
git checkout patch-1

# add the test case

git add .
git commit -m "add test"
git push
```

Patch:
diff --git a/expandvars.py b/expandvars.py
index 0f3254a..ae1f4aa 100644
--- a/expandvars.py
+++ b/expandvars.py
@@ -392,7 +392,7 @@ def expand_default(var, vars_, set_, nounset, indirect, environ, var_symbol):
     for c in vars_:
         if c == "}":
             n = len(default) + 1
-            default_ = "".join(default)
+            default_ = expand("".join(default))
             if set_ and var not in environ:
                 environ.update({var: default_})
             return getenv(


Test patch:
diff --git a/tests/test_expandvars.py b/tests/test_expandvars.py
index 49f5e21..b95d639 100644
--- a/tests/test_expandvars.py
+++ b/tests/test_expandvars.py
@@ -62,7 +62,7 @@ def test_expandvars_pid():
     assert expandvars.expandvars("PID( $$ )") == "PID( {0} )".format(getpid())
 
 
-@patch.dict(env, {})
+@patch.dict(env, {"ALTERNATE": "Alternate"})
 def test_expandvars_get_default():
     importlib.reload(expandvars)
 
@@ -70,6 +70,7 @@ def test_expandvars_get_default():
     assert expandvars.expandvars("${FOO:-default}") == "default"
     assert expandvars.expandvars("${FOO:-}") == ""
     assert expandvars.expandvars("${FOO:-foo}:${FOO-bar}") == "foo:bar"
+    assert expandvars.expandvars("${FOO:-$ALTERNATE}") == "Alternate"
 
 
 @patch.dict(env, {})