Skip to content

Commit

Permalink
Escape % symbol in supervisor exporter
Browse files Browse the repository at this point in the history
As reported in #73, the % symbol needs to be escaped in the command or
in env var values when exporting to supervisord.

Fixes #73.
  • Loading branch information
nickstenning committed Apr 10, 2016
1 parent d0b551f commit 9ba365d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions honcho/export/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ def dashrepl(value):
return re.sub(patt, '-', value)


def percentescape(value):
"""
Double any % signs.
"""
return value.replace('%', '%%')


def _default_template_env(loader):
env = jinja2.Environment(loader=loader)
env.filters['shellquote'] = shellquote
env.filters['dashrepl'] = dashrepl
env.filters['percentescape'] = percentescape
return env
4 changes: 2 additions & 2 deletions honcho/export/templates/supervisord/supervisord.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% for p in processes -%}
[program:{{ p.name|dashrepl }}]
command={{ shell }} -c '{{ p.cmd }}'
command={{ shell }} -c '{{ p.cmd|percentescape }}'
autostart=true
autorestart=true
stopsignal=QUIT
Expand All @@ -10,7 +10,7 @@ user={{ user }}
directory={{ app_root }}
environment=
{%- for key,value in p.env.items() -%}
{{ key }}={{ value|shellquote }}
{{ key }}={{ value|shellquote|percentescape }}
{%- if not loop.last %},{% endif %}
{%- endfor %}

Expand Down
11 changes: 11 additions & 0 deletions tests/test_export_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from honcho.export.base import BaseExport
from honcho.export.base import dashrepl
from honcho.export.base import percentescape


class GiraffeExport(BaseExport):
Expand Down Expand Up @@ -45,3 +46,13 @@ def test_get_template(self):
))
def test_dashrepl(name_in, name_out):
assert dashrepl(name_in) == name_out


@pytest.mark.parametrize('val_in,val_out', (
('foo', 'foo'),
('foo name.%h', 'foo name.%%h'),
('%one two% %three', '%%one two%% %%three'),
('foo%%bar', 'foo%%%%bar'),
))
def test_percentescape(val_in, val_out):
assert percentescape(val_in) == val_out

0 comments on commit 9ba365d

Please sign in to comment.