Blob Blame Raw
From ae413b03a9c05374ace146d2876d9bc11ad5648f Mon Sep 17 00:00:00 2001
From: Dominic Cleal <dcleal@redhat.com>
Date: Fri, 5 Sep 2014 08:39:31 +0100
Subject: [PATCH] Systemd: parse environment variables where only value is
 quoted

Fixes regression introduced in 5226ae7, which added support to parse fully
quoted "NAME=value" environment vars.  To support both, this commit stores
the quotes in the value if it's only the value quoted.

Fixes RHBZ#1138508

(cherry picked from commit f64d8bc7a7670f3af2549fdcefb64c2b5f22cd0d)
---
 lenses/systemd.aug            | 4 +++-
 lenses/tests/test_systemd.aug | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lenses/systemd.aug b/lenses/systemd.aug
index e1d9e5a..ade70d5 100644
--- a/lenses/systemd.aug
+++ b/lenses/systemd.aug
@@ -132,9 +132,11 @@ let entry_env =
      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\\]/)?)
+  in let bare_dqval = envkv (store /"[^#" \t\n]*[^#" \t\n\\]"/)
+  in let bare_sqval = 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 let envkv_quoted = [ bare ] | [ bare_dqval ] | [ bare_sqval ] | [ 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 82516b3..3397456 100644
--- a/lenses/tests/test_systemd.aug
+++ b/lenses/tests/test_systemd.aug
@@ -204,6 +204,8 @@ Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETA
 Environment=LANG=C\
 FOO=BAR
 Environment=\"LANG=foo bar\" FOO=BAR
+Environment=OPTIONS=\"-LS0-6d\"
+Environment=OPTIONS='-LS0-6d'
 "
 (* Test: Systemd.lns *)
 test Systemd.lns get env =
@@ -239,6 +241,12 @@ test Systemd.lns get env =
       { "LANG" = "foo bar" }
       { "FOO" = "BAR" }
     }
+    { "Environment"
+      { "OPTIONS" = "\"-LS0-6d\"" }
+    }
+    { "Environment"
+      { "OPTIONS" = "'-LS0-6d'" }
+    }
   }
 
 (* Variable: unit *)