Commit 6fe0ab3
committed
Fix Base45 dropping trailing bytes on non-ASCII input
The Base45 encoder and decoder iterated with range(0, len(text), step)
while indexing into t = b(text). codext converts a bytes input to str
(UTF-8) before the codec runs, so for any non-ASCII content b(text) is
longer than text and len(text) stops the loop early, silently dropping
the trailing byte(s). For example encode(b'\xcf\xb1\x1b') returned
'OBQ' instead of 'OBQR0' and the value no longer round-tripped.
Iterate over len(t) (the actual byte sequence) instead. Output now
matches RFC 9285 and the reference base45 implementation, and encoding
round-trips for arbitrary byte input.1 parent 578f57d commit 6fe0ab3
2 files changed
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
| |||
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
57 | | - | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
214 | 227 | | |
215 | 228 | | |
216 | 229 | | |
| |||
0 commit comments