From 61cd5cc82b311aa4e1a243f8aeb99f72895de08b Mon Sep 17 00:00:00 2001 From: Arie van Luttikhuizen Date: Wed, 5 Dec 2018 15:00:00 -0800 Subject: [PATCH] Fixed directives with spaces not being quoted --- crossplane/builder.py | 5 +---- tests/configs/directive-with-space/nginx.conf | 8 ++++++++ tests/test_build.py | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 tests/configs/directive-with-space/nginx.conf diff --git a/crossplane/builder.py b/crossplane/builder.py index 6dbe86f..4cb3831 100644 --- a/crossplane/builder.py +++ b/crossplane/builder.py @@ -96,10 +96,7 @@ def _build_lines(objs): state['depth'] = state['depth'] + 1 for obj in objs: - directive = obj['directive'] - - if directive == '': - directive = _enquote(directive) + directive = _enquote(obj['directive']) if directive in EXTERNAL_BUILDERS: external_builder = EXTERNAL_BUILDERS[directive] diff --git a/tests/configs/directive-with-space/nginx.conf b/tests/configs/directive-with-space/nginx.conf new file mode 100644 index 0000000..f187048 --- /dev/null +++ b/tests/configs/directive-with-space/nginx.conf @@ -0,0 +1,8 @@ +events { +} +http { + map $http_user_agent $mobile { + default 0; + '~Opera Mini' 1; + } +} diff --git a/tests/test_build.py b/tests/test_build.py index 9c09443..45a35a2 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -256,3 +256,7 @@ def test_compare_parsed_and_built_russian_text(tmpdir): def test_compare_parsed_and_built_quoted_right_brace(tmpdir): compare_parsed_and_built('quoted-right-brace', 'nginx.conf', tmpdir) + + +def test_compare_parsed_and_built_directive_with_space(tmpdir): + compare_parsed_and_built('directive-with-space', 'nginx.conf', tmpdir)