Blob Blame History Raw
From ff36da46e07b819cf178f66c284a2672f547b6cb Mon Sep 17 00:00:00 2001
From: Dominic Cleal <dcleal@redhat.com>
Date: Wed, 9 Jul 2014 09:22:44 +0100
Subject: [PATCH] Systemd: allow quoted Environment key=value pairs

Fixes RHBZ#1100547

(cherry picked from commit 5226ae7d162691c20e00096ae8023e74b912ace0)

Conflicts:
	NEWS
---
 lenses/systemd.aug            | 9 +++++++--
 lenses/tests/test_systemd.aug | 6 +++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lenses/systemd.aug b/lenses/systemd.aug
index c7f9f9d..370945b 100644
--- a/lenses/systemd.aug
+++ b/lenses/systemd.aug
@@ -125,8 +125,13 @@ let entry_command =
 (* View: entry_env
    Entry that takes a space separated set of ENV=value key/value pairs *)
 let entry_env =
-     let envkv = [ key env_key . Util.del_str "=" . ( sto_value )? ]
-  in entry_fn entry_env_kw ( Build.opt_list envkv value_sep )
+     let envkv (env_val:lens) = key env_key . Util.del_str "=" . env_val
+     (* bare has no spaces, and is optionally quoted *)
+  in let bare = Quote.do_quote_opt (envkv (store /[^;#'" \t\n]*[^;#'" \t\n\\]/)?)
+     (* quoted has at least one space, and must be quoted *)
+  in let quoted = Quote.do_quote (envkv (store /[^;#"'\n]*[ \t]+[^;#"'\n]*/))
+  in let envkv_quoted = [ bare ] | [ quoted ]
+  in entry_fn entry_env_kw ( Build.opt_list envkv_quoted value_sep )
 
 
 (************************************************************************
diff --git a/lenses/tests/test_systemd.aug b/lenses/tests/test_systemd.aug
index a531230..b1574e1 100644
--- a/lenses/tests/test_systemd.aug
+++ b/lenses/tests/test_systemd.aug
@@ -203,6 +203,7 @@ Environment=LANG=C FOO=BAR
 Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
 Environment=LANG=C\
 FOO=BAR
+Environment=\"LANG=foo bar\" FOO=BAR
 "
 (* Test: Systemd.lns *)
 test Systemd.lns get env =
@@ -234,6 +235,10 @@ test Systemd.lns get env =
       { "LANG" = "C" }
       { "FOO" = "BAR" }
     }
+    { "Environment"
+      { "LANG" = "foo bar" }
+      { "FOO" = "BAR" }
+    }
   }
 
 (* Variable: unit *)
@@ -302,4 +307,3 @@ test Systemd.entry_command get "ExecStart=/usr/bin/find /var/lib/sudo -exec /usr
       { "7" = "\073" }
     }
   }
-