Blob Blame History Raw
From 909c71ba2ce1fd294acc0c456e22514fd6262e39 Mon Sep 17 00:00:00 2001
From: Dominic Cleal <dcleal@redhat.com>
Date: Wed, 9 Jul 2014 09:22:57 +0100
Subject: [PATCH] Shellvars: support $(( .. )) arithmetic expansion in variable
 assignment

Fixes RHBZ#1100550

(cherry picked from commit 5ef5e32c7e9e3c220325542ee9b0174f151c615d)

Conflicts:
	NEWS
	lenses/shellvars.aug
	lenses/tests/test_shellvars.aug
---
 lenses/shellvars.aug            | 5 +++--
 lenses/tests/test_shellvars.aug | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index 815e4f1..511b045 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -37,7 +37,8 @@ module Shellvars =
   let bquot = /`[^`\n]*`/
   (* dbquot don't take spaces or semi-colons *)
   let dbquot = /``[^` \t\n;]+``/
-  let dollar_assign = /\$\([^\)#\n]*\)/
+  let dollar_assign = /\$\([^\(\)#\n]*\)/
+  let dollar_arithm = /\$\(\([^\)#\n]*\)\)/
 
   let sto_to_semicol = store /[^#; \t\n][^#;\n]+[^#; \t\n]|[^#; \t\n]+/
 
@@ -56,7 +57,7 @@ module Shellvars =
   let simple_value =
     let empty_array = /\([ \t]*\)/ in
       store (char* | (dquot | squot)+
-            | bquot | dbquot | dollar_assign | empty_array)
+            | bquot | dbquot | dollar_assign | dollar_arithm | empty_array)
 
   let export = [ key "export" . Util.del_ws_spc ]
   let kv = Util.indent . export? . key key_re
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 18fd361..be852ae 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -457,6 +457,11 @@ esac\n" =
       { "@case_entry" = "1"
         { "TestVar" = "\"test1\"" } } }
 
+  (* Support $(( .. )) arithmetic expansion in variable assignment, RHBZ#1100550 *)
+  test lns get "export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))\n" =
+    { "MALLOC_PERTURB_" = "$(($RANDOM % 255 + 1))"
+      { "export" } }
+
 (* Local Variables: *)
 (* mode: caml       *)
 (* End:             *)