7 Bug-Reported-by: Clark Wang <dearvoid@gmail.com>
8 Bug-Reference-ID: <CADv8-ojttPUFOZXqbjsvy83LfaJtQKZ5qejGdF6j0VJ3vtrYOA@mail.gmail.com>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2016-11/msg00106.html
13 When -N is used, the input is not supposed to be split using $IFS, but
14 leading and trailing IFS whitespace was still removed.
16 Patch (apply with `patch -p0'):
18 *** ../bash-4.4-patched/subst.c 2017-01-20 14:22:01.000000000 -0500
19 --- subst.c 2017-01-25 13:43:22.000000000 -0500
22 /* Parse a single word from STRING, using SEPARATORS to separate fields.
23 ENDPTR is set to the first character after the word. This is used by
24 ! the `read' builtin. This is never called with SEPARATORS != $IFS;
25 ! it should be simplified.
27 XXX - this function is very similar to list_string; they should be
30 get_word_from_string (stringp, separators, endptr)
32 /* Parse a single word from STRING, using SEPARATORS to separate fields.
33 ENDPTR is set to the first character after the word. This is used by
36 ! This is never called with SEPARATORS != $IFS, and takes advantage of that.
38 XXX - this function is very similar to list_string; they should be
41 + #define islocalsep(c) (local_cmap[(unsigned char)(c)] != 0)
44 get_word_from_string (stringp, separators, endptr)
49 int sindex, sh_style_split, whitesep, xflags;
50 + unsigned char local_cmap[UCHAR_MAX+1]; /* really only need single-byte chars here */
55 separators[2] == '\n' &&
56 separators[3] == '\0';
57 ! for (xflags = 0, s = ifs_value; s && *s; s++)
59 if (*s == CTLESC) xflags |= SX_NOCTLESC;
60 if (*s == CTLNUL) xflags |= SX_NOESCCTLNUL;
64 separators[2] == '\n' &&
65 separators[3] == '\0';
66 ! memset (local_cmap, '\0', sizeof (local_cmap));
67 ! for (xflags = 0, s = separators; s && *s; s++)
69 if (*s == CTLESC) xflags |= SX_NOCTLESC;
70 if (*s == CTLNUL) xflags |= SX_NOESCCTLNUL;
71 + local_cmap[(unsigned char)*s] = 1; /* local charmap of separators */
77 /* Remove sequences of whitespace at the beginning of STRING, as
78 ! long as those characters appear in IFS. */
79 ! if (sh_style_split || !separators || !*separators)
81 ! for (; *s && spctabnl (*s) && isifs (*s); s++);
83 /* If the string is nothing but whitespace, update it and return. */
86 /* Remove sequences of whitespace at the beginning of STRING, as
87 ! long as those characters appear in SEPARATORS. This happens if
88 ! SEPARATORS == $' \t\n' or if IFS is unset. */
89 ! if (sh_style_split || separators == 0)
91 ! for (; *s && spctabnl (*s) && islocalsep (*s); s++);
93 /* If the string is nothing but whitespace, update it and return. */
96 This obeys the field splitting rules in Posix.2. */
98 ! /* Don't need string length in ADVANCE_CHAR or string_extract_verbatim
99 ! unless multibyte chars are possible. */
100 ! slen = (MB_CUR_MAX > 1) ? STRLEN (s) : 1;
101 current_word = string_extract_verbatim (s, slen, &sindex, separators, xflags);
104 This obeys the field splitting rules in Posix.2. */
106 ! /* Don't need string length in ADVANCE_CHAR unless multibyte chars are
107 ! possible, but need it in string_extract_verbatim for bounds checking */
109 current_word = string_extract_verbatim (s, slen, &sindex, separators, xflags);
113 /* Now skip sequences of space, tab, or newline characters if they are
114 in the list of separators. */
115 ! while (s[sindex] && spctabnl (s[sindex]) && isifs (s[sindex]))
119 /* Now skip sequences of space, tab, or newline characters if they are
120 in the list of separators. */
121 ! while (s[sindex] && spctabnl (s[sindex]) && islocalsep (s[sindex]))
126 delimiter, not a separate delimiter that would result in an empty field.
127 Look at POSIX.2, 3.6.5, (3)(b). */
128 ! if (s[sindex] && whitesep && isifs (s[sindex]) && !spctabnl (s[sindex]))
131 /* An IFS character that is not IFS white space, along with any adjacent
132 IFS white space, shall delimit a field. */
133 ! while (s[sindex] && spctabnl (s[sindex]) && isifs (s[sindex]))
137 delimiter, not a separate delimiter that would result in an empty field.
138 Look at POSIX.2, 3.6.5, (3)(b). */
139 ! if (s[sindex] && whitesep && islocalsep (s[sindex]) && !spctabnl (s[sindex]))
142 /* An IFS character that is not IFS white space, along with any adjacent
143 IFS white space, shall delimit a field. */
144 ! while (s[sindex] && spctabnl (s[sindex]) && islocalsep(s[sindex]))
147 *** ../bash-4.4/patchlevel.h 2016-06-22 14:51:03.000000000 -0400
148 --- patchlevel.h 2016-10-01 11:01:28.000000000 -0400
151 looks for to find the patch level (for the sccs version string). */
153 ! #define PATCHLEVEL 11
155 #endif /* _PATCHLEVEL_H_ */
157 looks for to find the patch level (for the sccs version string). */
159 ! #define PATCHLEVEL 12
161 #endif /* _PATCHLEVEL_H_ */