rcolebaugh / rpms / bash

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