Repository navigation
Commit 35fe452
committed
Follow CPython's padding rules in a2b_base64
With strict_mode=True the decoder accepted padding CPython rejects:
>>> binascii.a2b_base64(b'YWJj=', strict_mode=True)
b'abc'
It also dropped data in the default mode, because it returned at the
first pad that completed a quad:
>>> binascii.a2b_base64(b'abc=a')
b'i\xb7' # CPython: b'i\xb7\x1a'
The loop now counts pads and decides at the end, the way CPython does,
so a stray pad is ignored outside strict mode and named as leading,
excess or discontinuous inside it. DecodeError::InvalidPadding was dead
in this file and now carries the excess padding message.
test_base64_strict_mode and test_base64_excess_data were marked as
expected failures and pass now.
Assisted-by: Claude Code:claude-opus-51 parent 3d2ee64 commit 35fe452
2 files changed
Lines changed: 40 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | 120 | | |
122 | 121 | | |
123 | 122 | | |
| |||
175 | 174 | | |
176 | 175 | | |
177 | 176 | | |
178 | | - | |
179 | 177 | | |
180 | 178 | | |
181 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | 294 | | |
299 | 295 | | |
300 | 296 | | |
301 | 297 | | |
302 | 298 | | |
303 | | - | |
304 | 299 | | |
305 | 300 | | |
306 | | - | |
307 | | - | |
308 | 301 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
314 | 306 | | |
315 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
316 | 311 | | |
317 | 312 | | |
318 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
319 | 326 | | |
320 | 327 | | |
321 | 328 | | |
| |||
327 | 334 | | |
328 | 335 | | |
329 | 336 | | |
330 | | - | |
331 | | - | |
332 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
333 | 345 | | |
334 | 346 | | |
335 | 347 | | |
| |||
361 | 373 | | |
362 | 374 | | |
363 | 375 | | |
364 | | - | |
365 | | - | |
366 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
367 | 379 | | |
368 | 380 | | |
369 | | - | |
370 | | - | |
| 381 | + | |
371 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
372 | 389 | | |
373 | 390 | | |
374 | 391 | | |
| |||
864 | 881 | | |
865 | 882 | | |
866 | 883 | | |
867 | | - | |
| 884 | + | |
868 | 885 | | |
869 | 886 | | |
870 | 887 | | |
| |||
0 commit comments