You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.4 KiB

  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 5.1
  4. Patch-ID: bash51-004
  5. Bug-Reported-by: oguzismailuysal@gmail.com
  6. Bug-Reference-ID: <CAH7i3LoHGmwaghDpCWRUfcY04gQmeDTH3RiG=bf2b=KbU=gyhw@mail.gmail.com>
  7. Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00039.html
  8. Bug-Description:
  9. If a key-value compound array assignment to an associative array is supplied
  10. as an assignment statement argument to the `declare' command that declares the
  11. array, the assignment doesn't perform the correct word expansions.
  12. This patch makes key-value assignment and subscript assignment perform the
  13. same expansions when they're supplied as an argument to `declare'.
  14. Patch (apply with `patch -p0'):
  15. --- a/arrayfunc.c
  16. +++ b/arrayfunc.c
  17. @@ -597,6 +597,27 @@ assign_assoc_from_kvlist (var, nlist, h,
  18. free (aval);
  19. }
  20. }
  21. +
  22. +/* Return non-zero if L appears to be a key-value pair associative array
  23. + compound assignment. */
  24. +int
  25. +kvpair_assignment_p (l)
  26. + WORD_LIST *l;
  27. +{
  28. + return (l && (l->word->flags & W_ASSIGNMENT) == 0 && l->word->word[0] != '['); /*]*/
  29. +}
  30. +
  31. +char *
  32. +expand_and_quote_kvpair_word (w)
  33. + char *w;
  34. +{
  35. + char *t, *r;
  36. +
  37. + t = w ? expand_assignment_string_to_string (w, 0) : 0;
  38. + r = sh_single_quote (t ? t : "");
  39. + free (t);
  40. + return r;
  41. +}
  42. #endif
  43. /* Callers ensure that VAR is not NULL. Associative array assignments have not
  44. @@ -640,7 +661,7 @@ assign_compound_array_list (var, nlist,
  45. last_ind = (a && (flags & ASS_APPEND)) ? array_max_index (a) + 1 : 0;
  46. #if ASSOC_KVPAIR_ASSIGNMENT
  47. - if (assoc_p (var) && nlist && (nlist->word->flags & W_ASSIGNMENT) == 0 && nlist->word->word[0] != '[') /*]*/
  48. + if (assoc_p (var) && kvpair_assignment_p (nlist))
  49. {
  50. iflags = flags & ~ASS_APPEND;
  51. assign_assoc_from_kvlist (var, nlist, nhash, iflags);
  52. --- a/arrayfunc.h
  53. +++ b/arrayfunc.h
  54. @@ -67,6 +67,9 @@ extern SHELL_VAR *assign_array_var_from_
  55. extern char *expand_and_quote_assoc_word PARAMS((char *, int));
  56. extern void quote_compound_array_list PARAMS((WORD_LIST *, int));
  57. +extern int kvpair_assignment_p PARAMS((WORD_LIST *));
  58. +extern char *expand_and_quote_kvpair_word PARAMS((char *));
  59. +
  60. extern int unbind_array_element PARAMS((SHELL_VAR *, char *, int));
  61. extern int skipsubscript PARAMS((const char *, int, int));
  62. --- a/subst.c
  63. +++ b/subst.c
  64. @@ -11604,6 +11604,7 @@ expand_oneword (value, flags)
  65. {
  66. WORD_LIST *l, *nl;
  67. char *t;
  68. + int kvpair;
  69. if (flags == 0)
  70. {
  71. @@ -11618,11 +11619,21 @@ expand_oneword (value, flags)
  72. {
  73. /* Associative array */
  74. l = parse_string_to_word_list (value, 1, "array assign");
  75. +#if ASSOC_KVPAIR_ASSIGNMENT
  76. + kvpair = kvpair_assignment_p (l);
  77. +#endif
  78. +
  79. /* For associative arrays, with their arbitrary subscripts, we have to
  80. expand and quote in one step so we don't have to search for the
  81. closing right bracket more than once. */
  82. for (nl = l; nl; nl = nl->next)
  83. {
  84. +#if ASSOC_KVPAIR_ASSIGNMENT
  85. + if (kvpair)
  86. + /* keys and values undergo the same set of expansions */
  87. + t = expand_and_quote_kvpair_word (nl->word->word);
  88. + else
  89. +#endif
  90. if ((nl->word->flags & W_ASSIGNMENT) == 0)
  91. t = sh_single_quote (nl->word->word ? nl->word->word : "");
  92. else
  93. --- a/patchlevel.h
  94. +++ b/patchlevel.h
  95. @@ -25,6 +25,6 @@
  96. regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
  97. looks for to find the patch level (for the sccs version string). */
  98. -#define PATCHLEVEL 3
  99. +#define PATCHLEVEL 4
  100. #endif /* _PATCHLEVEL_H_ */