diff --git a/.travis.yml b/.travis.yml index f0d9a023..ef69836f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,7 +66,7 @@ jobs: stage: installation tests install: skip script: ./tests/docker/build - env: DISTRO=centos-latest PYVER=2 + env: DISTRO=centos-latest PYVER=3 # Ubuntu, latest - <<: *installation-stage diff --git a/CHANGES.rst b/CHANGES.rst index b5efd82f..c62cd635 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,13 @@ Change log .. note:: **Upgrade notes**: after upgrading, run the ``arouteserver setup-templates`` command to sync the local templates with those distributed with the new version. More details on the `Upgrading `__ section of the documentation. +v0.22.2 +------- + +- Fix: prevent environment variables with unknown escapes (like `\u`) from interrupting the execution. + + Related: `issue #50 on GitHub `_. + v0.22.1 ------- diff --git a/pierky/arouteserver/config/base.py b/pierky/arouteserver/config/base.py index d9ff3157..440a4039 100644 --- a/pierky/arouteserver/config/base.py +++ b/pierky/arouteserver/config/base.py @@ -77,8 +77,7 @@ def expand_include(lines): def expand_env_vars(doc): res = doc - for v in os.environ: - res = re.sub("\$\{" + v + "\}", os.environ[v], res) + res = os.path.expandvars(res) res = re.sub("\$\{[A-Za-z0-9_]+\}", "", res) return res diff --git a/pierky/arouteserver/version.py b/pierky/arouteserver/version.py index 4e5b78be..be578d87 100644 --- a/pierky/arouteserver/version.py +++ b/pierky/arouteserver/version.py @@ -13,5 +13,5 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = "0.22.1" # pragma: no cover +__version__ = "0.22.2-alpha3" # pragma: no cover COPYRIGHT_YEAR = 2019 # pragma: no cover diff --git a/tests/docker/centos-latest_py2.m4 b/tests/docker/centos-latest_py3.m4 similarity index 70% rename from tests/docker/centos-latest_py2.m4 rename to tests/docker/centos-latest_py3.m4 index 7667a835..69808380 100644 --- a/tests/docker/centos-latest_py2.m4 +++ b/tests/docker/centos-latest_py3.m4 @@ -4,8 +4,11 @@ include(`base.m4') RUN yum -y update && yum -y install epel-release RUN yum -y update && yum -y install \ - python-pip \ - python-devel \ + python3-pip \ + python3-devel \ gcc +ENV python=python3 +ENV pip=pip3 + include(`install.m4') diff --git a/tests/static/test_cfg_general.py b/tests/static/test_cfg_general.py index ac45422a..57d3a9f1 100644 --- a/tests/static/test_cfg_general.py +++ b/tests/static/test_cfg_general.py @@ -1411,3 +1411,20 @@ def test_env_vars_corrupted(self): " router_id: ${ROUTER_ID\n" ) self._contains_err("Invalid IPv4 address: ${ROUTER_ID") + + @mock.patch.dict(os.environ, {"ROUTER_ID": "192.0.2.1", "BAD_ESCAPE": r"\u"}) + def test_env_vars_bad_escape(self): + """{}: environment variables: ok (bad escape)""" + + self.cfg._load_from_yaml( + "cfg:\n" + " rs_as: 999\n" + " router_id: ${ROUTER_ID}\n" + " filtering:\n" + " global_black_list_pref: ${GLOBAL_BLACK_LIST_PREF}\n" + ) + self.cfg.parse() + self._contains_err() + + self.assertEqual(self.cfg["router_id"], "192.0.2.1") + self.assertEqual(self.cfg["filtering"]["global_black_list_pref"], None)