1
0

110-upstream-bash43-010.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 4.3
  4. Patch-ID: bash43-010
  5. Bug-Reported-by: Albert Shih <Albert.Shih@obspm.fr>
  6. Bug-Reference-ID: Wed, 5 Mar 2014 23:01:40 +0100
  7. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2014-03/msg00028.html
  8. Bug-Description:
  9. Patch (apply with `patch -p0'):
  10. This patch changes the behavior of programmable completion to compensate
  11. for two assumptions made by the bash-completion package. Bash-4.3 changed
  12. to dequote the argument to programmable completion only under certain
  13. circumstances, to make the behavior of compgen more consistent when run
  14. from the command line -- closer to the behavior when run by a shell function
  15. run as part of programmable completion. Bash-completion can pass quoted
  16. arguments to compgen when the original word to be completed was not quoted,
  17. expecting programmable completion to dequote the word before attempting
  18. completion.
  19. This patch fixes two cases:
  20. 1. An empty string that bash-completion passes to compgen as a quoted null
  21. string ('').
  22. 2. An unquoted word that bash-completion quotes using single quotes or
  23. backslashes before passing it to compgen.
  24. In these cases, since readline did not detect a quote character in the original
  25. word to be completed, bash-4.3
  26. --- a/externs.h
  27. +++ b/externs.h
  28. @@ -324,6 +324,7 @@ extern char *sh_un_double_quote __P((cha
  29. extern char *sh_backslash_quote __P((char *, const char *, int));
  30. extern char *sh_backslash_quote_for_double_quotes __P((char *));
  31. extern int sh_contains_shell_metas __P((char *));
  32. +extern int sh_contains_quotes __P((char *));
  33. /* declarations for functions defined in lib/sh/spell.c */
  34. extern int spname __P((char *, char *));
  35. --- a/lib/sh/shquote.c
  36. +++ b/lib/sh/shquote.c
  37. @@ -311,3 +311,17 @@ sh_contains_shell_metas (string)
  38. return (0);
  39. }
  40. +
  41. +int
  42. +sh_contains_quotes (string)
  43. + char *string;
  44. +{
  45. + char *s;
  46. +
  47. + for (s = string; s && *s; s++)
  48. + {
  49. + if (*s == '\'' || *s == '"' || *s == '\\')
  50. + return 1;
  51. + }
  52. + return 0;
  53. +}
  54. --- a/pcomplete.c
  55. +++ b/pcomplete.c
  56. @@ -183,6 +183,7 @@ ITEMLIST it_variables = { LIST_DYNAMIC,
  57. COMPSPEC *pcomp_curcs;
  58. const char *pcomp_curcmd;
  59. +const char *pcomp_curtxt;
  60. #ifdef DEBUG
  61. /* Debugging code */
  62. @@ -753,6 +754,32 @@ pcomp_filename_completion_function (text
  63. quoted strings. */
  64. dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
  65. }
  66. + /* Intended to solve a mismatched assumption by bash-completion. If
  67. + the text to be completed is empty, but bash-completion turns it into
  68. + a quoted string ('') assuming that this code will dequote it before
  69. + calling readline, do the dequoting. */
  70. + else if (iscompgen && iscompleting &&
  71. + pcomp_curtxt && *pcomp_curtxt == 0 &&
  72. + text && (*text == '\'' || *text == '"') && text[1] == text[0] && text[2] == 0 &&
  73. + rl_filename_dequoting_function)
  74. + dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
  75. + /* Another mismatched assumption by bash-completion. If compgen is being
  76. + run as part of bash-completion, and the argument to compgen is not
  77. + the same as the word originally passed to the programmable completion
  78. + code, dequote the argument if it has quote characters. It's an
  79. + attempt to detect when bash-completion is quoting its filename
  80. + argument before calling compgen. */
  81. + /* We could check whether gen_shell_function_matches is in the call
  82. + stack by checking whether the gen-shell-function-matches tag is in
  83. + the unwind-protect stack, but there's no function to do that yet.
  84. + We could simply check whether we're executing in a function by
  85. + checking variable_context, and may end up doing that. */
  86. + else if (iscompgen && iscompleting && rl_filename_dequoting_function &&
  87. + pcomp_curtxt && text &&
  88. + STREQ (pcomp_curtxt, text) == 0 &&
  89. + variable_context &&
  90. + sh_contains_quotes (text)) /* guess */
  91. + dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
  92. else
  93. dfn = savestring (text);
  94. }
  95. @@ -1522,7 +1549,7 @@ gen_progcomp_completions (ocmd, cmd, wor
  96. COMPSPEC **lastcs;
  97. {
  98. COMPSPEC *cs, *oldcs;
  99. - const char *oldcmd;
  100. + const char *oldcmd, *oldtxt;
  101. STRINGLIST *ret;
  102. cs = progcomp_search (ocmd);
  103. @@ -1545,14 +1572,17 @@ gen_progcomp_completions (ocmd, cmd, wor
  104. oldcs = pcomp_curcs;
  105. oldcmd = pcomp_curcmd;
  106. + oldtxt = pcomp_curtxt;
  107. pcomp_curcs = cs;
  108. pcomp_curcmd = cmd;
  109. + pcomp_curtxt = word;
  110. ret = gen_compspec_completions (cs, cmd, word, start, end, foundp);
  111. pcomp_curcs = oldcs;
  112. pcomp_curcmd = oldcmd;
  113. + pcomp_curtxt = oldtxt;
  114. /* We need to conditionally handle setting *retryp here */
  115. if (retryp)
  116. --- a/patchlevel.h
  117. +++ b/patchlevel.h
  118. @@ -25,6 +25,6 @@
  119. regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
  120. looks for to find the patch level (for the sccs version string). */
  121. -#define PATCHLEVEL 9
  122. +#define PATCHLEVEL 10
  123. #endif /* _PATCHLEVEL_H_ */