Commit 869da5e
committed
fix(printf): implement selective dollar-quoting for %q format
Fixes CI failure from PR #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 869da5e
File tree
2 files changed
+29
-45
lines changed- src/uucore/src/lib/features/quoting_style
- tests/by-util
2 files changed
+29
-45
lines changedLines changed: 22 additions & 39 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 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
177 | 154 | | |
| 155 | + | |
178 | 156 | | |
179 | 157 | | |
180 | 158 | | |
| |||
196 | 174 | | |
197 | 175 | | |
198 | 176 | | |
199 | | - | |
| 177 | + | |
| 178 | + | |
200 | 179 | | |
| 180 | + | |
201 | 181 | | |
202 | 182 | | |
203 | | - | |
204 | | - | |
| 183 | + | |
| 184 | + | |
205 | 185 | | |
206 | 186 | | |
207 | 187 | | |
208 | 188 | | |
209 | 189 | | |
210 | | - | |
| 190 | + | |
211 | 191 | | |
212 | 192 | | |
213 | 193 | | |
| |||
236 | 216 | | |
237 | 217 | | |
238 | 218 | | |
| 219 | + | |
| 220 | + | |
239 | 221 | | |
240 | | - | |
| 222 | + | |
241 | 223 | | |
242 | 224 | | |
243 | 225 | | |
| |||
286 | 268 | | |
287 | 269 | | |
288 | 270 | | |
| 271 | + | |
289 | 272 | | |
290 | 273 | | |
291 | 274 | | |
| |||
| 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