bash-5.1-patch-4.patch 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. diff --git a/arrayfunc.c b/arrayfunc.c
  2. --- a/arrayfunc.c
  3. +++ b/arrayfunc.c
  4. @@ -597,6 +597,27 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
  5. free (aval);
  6. }
  7. }
  8. +
  9. +/* Return non-zero if L appears to be a key-value pair associative array
  10. + compound assignment. */
  11. +int
  12. +kvpair_assignment_p (l)
  13. + WORD_LIST *l;
  14. +{
  15. + return (l && (l->word->flags & W_ASSIGNMENT) == 0 && l->word->word[0] != '['); /*]*/
  16. +}
  17. +
  18. +char *
  19. +expand_and_quote_kvpair_word (w)
  20. + char *w;
  21. +{
  22. + char *t, *r;
  23. +
  24. + t = w ? expand_assignment_string_to_string (w, 0) : 0;
  25. + r = sh_single_quote (t ? t : "");
  26. + free (t);
  27. + return r;
  28. +}
  29. #endif
  30. /* Callers ensure that VAR is not NULL. Associative array assignments have not
  31. @@ -640,7 +661,7 @@ assign_compound_array_list (var, nlist, flags)
  32. last_ind = (a && (flags & ASS_APPEND)) ? array_max_index (a) + 1 : 0;
  33. #if ASSOC_KVPAIR_ASSIGNMENT
  34. - if (assoc_p (var) && nlist && (nlist->word->flags & W_ASSIGNMENT) == 0 && nlist->word->word[0] != '[') /*]*/
  35. + if (assoc_p (var) && kvpair_assignment_p (nlist))
  36. {
  37. iflags = flags & ~ASS_APPEND;
  38. assign_assoc_from_kvlist (var, nlist, nhash, iflags);
  39. diff --git a/arrayfunc.h b/arrayfunc.h
  40. --- a/arrayfunc.h
  41. +++ b/arrayfunc.h
  42. @@ -67,6 +67,9 @@ extern SHELL_VAR *assign_array_var_from_string PARAMS((SHELL_VAR *, char *, int)
  43. extern char *expand_and_quote_assoc_word PARAMS((char *, int));
  44. extern void quote_compound_array_list PARAMS((WORD_LIST *, int));
  45. +extern int kvpair_assignment_p PARAMS((WORD_LIST *));
  46. +extern char *expand_and_quote_kvpair_word PARAMS((char *));
  47. +
  48. extern int unbind_array_element PARAMS((SHELL_VAR *, char *, int));
  49. extern int skipsubscript PARAMS((const char *, int, int));
  50. diff --git a/patchlevel.h b/patchlevel.h
  51. --- a/patchlevel.h
  52. +++ b/patchlevel.h
  53. @@ -25,6 +25,6 @@
  54. regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
  55. looks for to find the patch level (for the sccs version string). */
  56. -#define PATCHLEVEL 3
  57. +#define PATCHLEVEL 4
  58. #endif /* _PATCHLEVEL_H_ */
  59. diff --git a/subst.c b/subst.c
  60. --- a/subst.c
  61. +++ b/subst.c
  62. @@ -11604,6 +11604,7 @@ expand_oneword (value, flags)
  63. {
  64. WORD_LIST *l, *nl;
  65. char *t;
  66. + int kvpair;
  67. if (flags == 0)
  68. {
  69. @@ -11618,11 +11619,21 @@ expand_oneword (value, flags)
  70. {
  71. /* Associative array */
  72. l = parse_string_to_word_list (value, 1, "array assign");
  73. +#if ASSOC_KVPAIR_ASSIGNMENT
  74. + kvpair = kvpair_assignment_p (l);
  75. +#endif
  76. +
  77. /* For associative arrays, with their arbitrary subscripts, we have to
  78. expand and quote in one step so we don't have to search for the
  79. closing right bracket more than once. */
  80. for (nl = l; nl; nl = nl->next)
  81. {
  82. +#if ASSOC_KVPAIR_ASSIGNMENT
  83. + if (kvpair)
  84. + /* keys and values undergo the same set of expansions */
  85. + t = expand_and_quote_kvpair_word (nl->word->word);
  86. + else
  87. +#endif
  88. if ((nl->word->flags & W_ASSIGNMENT) == 0)
  89. t = sh_single_quote (nl->word->word ? nl->word->word : "");
  90. else