• R/O
  • SSH
  • HTTPS

yash: 提交


Commit MetaInfo

修訂4083 (tree)
時間2020-09-24 21:50:15
作者magicant

Log Message

Quoting inside parameter expansion inside double-quotes (#40751)

Change Summary

差異

--- yash/trunk/NEWS (revision 4082)
+++ yash/trunk/NEWS (revision 4083)
@@ -13,6 +13,10 @@
1313 = Quote removal in arithmetic expansion has been modified to match
1414 the behavior defined in POSIX. It no longer allows things like
1515 $(("2" + \5)).
16+ = The quotation rules for the substitution word in a parameter
17+ expansion inside double-quotes have been changed to match with
18+ the behavior of other existing shells. For example, "${x-\a'b'}"
19+ now expands to \a'b' rather than ab.
1620 * The "command" built-in with the -v or -V option was printing
1721 the pathnames of external commands with a redundant leading slash
1822 when the current working directory is "/" or "//".
--- yash/trunk/expand.c (revision 4082)
+++ yash/trunk/expand.c (revision 4083)
@@ -88,7 +88,7 @@
8888 __attribute__((nonnull));
8989 static void **trim_array(void **a, ssize_t startindex, ssize_t endindex)
9090 __attribute__((nonnull));
91-static void print_subst_as_error(const paramexp_T *p)
91+static void print_subst_as_error(const paramexp_T *p, quoting_T quoting)
9292 __attribute__((nonnull));
9393 static void match_each(void **restrict slist, const wchar_t *restrict pattern,
9494 paramexptype_T type)
@@ -405,8 +405,12 @@
405405 while (*ss != L'\0') {
406406 switch (*ss) {
407407 case L'"':
408- if (quoting != Q_WORD)
409- goto default_;
408+ switch (quoting) {
409+ case Q_WORD: case Q_DQPARAM:
410+ break;
411+ case Q_INDQ: case Q_LITERAL:
412+ goto default_;
413+ }
410414 indq = !indq;
411415 wb_wccat(&e->valuebuf, L'"');
412416 sb_ccat(&e->ccbuf, defaultcc | CC_QUOTATION);
@@ -430,6 +434,10 @@
430434 if (indq && wcschr(CHARS_ESCAPABLE, ss[1]) == NULL)
431435 goto default_;
432436 break;
437+ case Q_DQPARAM:
438+ if (wcschr(CHARS_ESCAPABLE "}", ss[1]) == NULL)
439+ goto default_;
440+ break;
433441 case Q_INDQ:
434442 if (wcschr(L"$`\\", ss[1]) == NULL)
435443 goto default_;
@@ -721,6 +729,7 @@
721729 unset = true;
722730
723731 /* PT_PLUS, PT_MINUS, PT_ASSIGN, PT_ERROR */
732+ quoting_T substq = indq ? Q_DQPARAM : Q_WORD;
724733 wchar_t *subst;
725734 switch (p->pe_type & PT_MASK) {
726735 case PT_PLUS:
@@ -732,7 +741,7 @@
732741 if (unset) {
733742 subst:
734743 plfree(values, free);
735- return expand_four_inner(p->pe_subst, TT_SINGLE, Q_WORD,
744+ return expand_four_inner(p->pe_subst, TT_SINGLE, substq,
736745 CC_SOFT_EXPANSION | (indq * CC_QUOTED), e);
737746 }
738747 break;
@@ -755,7 +764,7 @@
755764 p->pe_name);
756765 return false;
757766 }
758- subst = expand_single(p->pe_subst, TT_SINGLE, Q_WORD, ES_NONE);
767+ subst = expand_single(p->pe_subst, TT_SINGLE, substq, ES_NONE);
759768 if (subst == NULL)
760769 return false;
761770 if (v.type != GV_ARRAY) {
@@ -781,7 +790,7 @@
781790 case PT_ERROR:
782791 if (unset) {
783792 plfree(values, free);
784- print_subst_as_error(p);
793+ print_subst_as_error(p, substq);
785794 return false;
786795 }
787796 break;
@@ -937,10 +946,11 @@
937946 }
938947
939948 /* Expands `p->pe_subst' and prints it as an error message. */
940-void print_subst_as_error(const paramexp_T *p)
949+void print_subst_as_error(const paramexp_T *p, quoting_T quoting)
941950 {
942951 if (p->pe_subst != NULL) {
943- wchar_t *subst = expand_single(p->pe_subst, TT_SINGLE, Q_WORD, ES_NONE);
952+ wchar_t *subst =
953+ expand_single(p->pe_subst, TT_SINGLE, quoting, ES_NONE);
944954 if (subst != NULL) {
945955 if (p->pe_type & PT_NEST)
946956 xerror(0, "%ls", subst);
--- yash/trunk/expand.h (revision 4082)
+++ yash/trunk/expand.h (revision 4083)
@@ -34,7 +34,11 @@
3434 typedef enum {
3535 Q_WORD, /* Single quotations, double quotations, and backslashes are
3636 recognized as in the normal word. */
37- Q_INDQ, /* The string is quoted as if it is inside a pair of double
37+ Q_DQPARAM, /* The string is treated as the substitution word of a parameter
38+ expansion inside a pair of double quotations: Double
39+ quotations are recognized, but single quotations are not.
40+ Backslashes are recognized only before $, `, ", \ or }. */
41+ Q_INDQ, /* The string is treated as if it is inside a pair of double
3842 quotations: Single and double quotations are not recognized.
3943 Backslashes are recognized only before a $, `, or \. */
4044 Q_LITERAL, /* No quotations are recognized. */
Show on old repository browser