Commit a72fe5f
committed
fix(printf): implement selective dollar-quoting for %q format
Fixes CI failure from PR uutils#9640 where GNU test suite update (commit ba3442f4f)
exposed fundamental design flaws in printf %q shell-quoting implementation.
Problem:
Original code pre-scanned for control characters and wrapped ENTIRE strings
in $'...' if ANY control char was present (e.g., "a\r" → $'a\r').
Solution:
Implemented selective quoting that only wraps control characters themselves
(e.g., "a\r" → a$'\r'), matching GNU coreutils behavior.
Key Changes:
- Removed has_control_chars() pre-scanning logic
- Never start in dollar mode - enter/exit dynamically
- Exit dollar mode when encountering regular chars (selective quoting)
- Keep consecutive control chars in single dollar quote
- Handle apostrophes by exiting dollar mode and using \' escape
- Updated test expectations to match selective quoting behavior
Examples:
- 'a\tb' → a$'\t'b (not $'a\tb')
- '\x01\x02\x03' → $'\001\002\003' (not $'\001'$'\002'$'\003')
- 'hello\x01world' → hello$'\001'world (not $'hello\001world')1 parent 084a4c2 commit a72fe5f
File tree
2 files changed
+43
-44
lines changed- src/uucore/src/lib/features/quoting_style
- tests/by-util
2 files changed
+43
-44
lines changedLines changed: 36 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | 134 | | |
145 | 135 | | |
146 | 136 | | |
147 | 137 | | |
148 | 138 | | |
149 | 139 | | |
150 | | - | |
| 140 | + | |
151 | 141 | | |
152 | | - | |
| 142 | + | |
153 | 143 | | |
154 | 144 | | |
155 | 145 | | |
156 | 146 | | |
157 | 147 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
168 | 157 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
175 | 169 | | |
176 | | - | |
177 | 170 | | |
| 171 | + | |
178 | 172 | | |
179 | 173 | | |
180 | 174 | | |
| |||
196 | 190 | | |
197 | 191 | | |
198 | 192 | | |
199 | | - | |
| 193 | + | |
| 194 | + | |
200 | 195 | | |
| 196 | + | |
201 | 197 | | |
202 | 198 | | |
203 | | - | |
204 | | - | |
| 199 | + | |
| 200 | + | |
205 | 201 | | |
206 | 202 | | |
207 | 203 | | |
208 | 204 | | |
209 | 205 | | |
210 | | - | |
| 206 | + | |
211 | 207 | | |
212 | 208 | | |
213 | 209 | | |
| |||
237 | 233 | | |
238 | 234 | | |
239 | 235 | | |
240 | | - | |
| 236 | + | |
| 237 | + | |
241 | 238 | | |
242 | 239 | | |
243 | 240 | | |
| |||
253 | 250 | | |
254 | 251 | | |
255 | 252 | | |
256 | | - | |
| 253 | + | |
257 | 254 | | |
258 | 255 | | |
259 | 256 | | |
| |||
286 | 283 | | |
287 | 284 | | |
288 | 285 | | |
| 286 | + | |
289 | 287 | | |
290 | 288 | | |
291 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
192 | | - | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
| |||
257 | 258 | | |
258 | 259 | | |
259 | 260 | | |
260 | | - | |
| 261 | + | |
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
268 | | - | |
| 269 | + | |
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
276 | | - | |
| 277 | + | |
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
280 | 281 | | |
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
284 | | - | |
| 285 | + | |
285 | 286 | | |
286 | 287 | | |
287 | 288 | | |
| |||
329 | 330 | | |
330 | 331 | | |
331 | 332 | | |
332 | | - | |
| 333 | + | |
333 | 334 | | |
334 | 335 | | |
335 | 336 | | |
| |||
0 commit comments