svashisht / rpms / bash

Forked from rpms/bash 6 years ago
Clone
4945b83
diff --git a/arrayfunc.c b/arrayfunc.c
4945b83
--- a/arrayfunc.c
4945b83
+++ b/arrayfunc.c
4945b83
@@ -597,6 +597,27 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
4945b83
 	free (aval);
4945b83
     }
4945b83
 }
4945b83
+
4945b83
+/* Return non-zero if L appears to be a key-value pair associative array
4945b83
+   compound assignment. */ 
4945b83
+int
4945b83
+kvpair_assignment_p (l)
4945b83
+     WORD_LIST *l;
4945b83
+{
4945b83
+  return (l && (l->word->flags & W_ASSIGNMENT) == 0 && l->word->word[0] != '[');	/*]*/
4945b83
+}
4945b83
+
4945b83
+char *
4945b83
+expand_and_quote_kvpair_word (w)
4945b83
+     char *w;
4945b83
+{
4945b83
+  char *t, *r;
4945b83
+
4945b83
+  t = w ? expand_assignment_string_to_string (w, 0) : 0;
4945b83
+  r = sh_single_quote (t ? t : "");
4945b83
+  free (t);
4945b83
+  return r;
4945b83
+}
4945b83
 #endif
4945b83
      
4945b83
 /* Callers ensure that VAR is not NULL. Associative array assignments have not
4945b83
@@ -640,7 +661,7 @@ assign_compound_array_list (var, nlist, flags)
4945b83
   last_ind = (a && (flags & ASS_APPEND)) ? array_max_index (a) + 1 : 0;
4945b83
 
4945b83
 #if ASSOC_KVPAIR_ASSIGNMENT
4945b83
-  if (assoc_p (var) && nlist && (nlist->word->flags & W_ASSIGNMENT) == 0 && nlist->word->word[0] != '[')	/*]*/
4945b83
+  if (assoc_p (var) && kvpair_assignment_p (nlist))
4945b83
     {
4945b83
       iflags = flags & ~ASS_APPEND;
4945b83
       assign_assoc_from_kvlist (var, nlist, nhash, iflags);
4945b83
diff --git a/arrayfunc.h b/arrayfunc.h
4945b83
--- a/arrayfunc.h
4945b83
+++ b/arrayfunc.h
4945b83
@@ -67,6 +67,9 @@ extern SHELL_VAR *assign_array_var_from_string PARAMS((SHELL_VAR *, char *, int)
4945b83
 extern char *expand_and_quote_assoc_word PARAMS((char *, int));
4945b83
 extern void quote_compound_array_list PARAMS((WORD_LIST *, int));
4945b83
 
4945b83
+extern int kvpair_assignment_p PARAMS((WORD_LIST *));
4945b83
+extern char *expand_and_quote_kvpair_word PARAMS((char *));
4945b83
+
4945b83
 extern int unbind_array_element PARAMS((SHELL_VAR *, char *, int));
4945b83
 extern int skipsubscript PARAMS((const char *, int, int));
4945b83
 
4945b83
diff --git a/patchlevel.h b/patchlevel.h
4945b83
--- a/patchlevel.h
4945b83
+++ b/patchlevel.h
4945b83
@@ -25,6 +25,6 @@
4945b83
    regexp `^#define[ 	]*PATCHLEVEL', since that's what support/mkversion.sh
4945b83
    looks for to find the patch level (for the sccs version string). */
4945b83
 
4945b83
-#define PATCHLEVEL 3
4945b83
+#define PATCHLEVEL 4
4945b83
 
4945b83
 #endif /* _PATCHLEVEL_H_ */
4945b83
diff --git a/subst.c b/subst.c
4945b83
--- a/subst.c
4945b83
+++ b/subst.c
4945b83
@@ -11604,6 +11604,7 @@ expand_oneword (value, flags)
4945b83
 {
4945b83
   WORD_LIST *l, *nl;
4945b83
   char *t;
4945b83
+  int kvpair;
4945b83
   
4945b83
   if (flags == 0)
4945b83
     {
4945b83
@@ -11618,11 +11619,21 @@ expand_oneword (value, flags)
4945b83
     {
4945b83
       /* Associative array */
4945b83
       l = parse_string_to_word_list (value, 1, "array assign");
4945b83
+#if ASSOC_KVPAIR_ASSIGNMENT
4945b83
+      kvpair = kvpair_assignment_p (l);
4945b83
+#endif
4945b83
+
4945b83
       /* For associative arrays, with their arbitrary subscripts, we have to
4945b83
 	 expand and quote in one step so we don't have to search for the
4945b83
 	 closing right bracket more than once. */
4945b83
       for (nl = l; nl; nl = nl->next)
4945b83
 	{
4945b83
+#if ASSOC_KVPAIR_ASSIGNMENT
4945b83
+	  if (kvpair)
4945b83
+	    /* keys and values undergo the same set of expansions */
4945b83
+	    t = expand_and_quote_kvpair_word (nl->word->word);
4945b83
+	  else
4945b83
+#endif
4945b83
 	  if ((nl->word->flags & W_ASSIGNMENT) == 0)
4945b83
 	    t = sh_single_quote (nl->word->word ? nl->word->word : "");
4945b83
 	  else