Repository navigation
Commit 41f49cf
authored
Escape bytearray contents as bytes in string literals (#817)
Passing `bytearray(b'ab')` as a query parameter currently sends the
Python text `bytearray(b'ab')` to the server. Escape the underlying two
bytes so the parameter behaves like `b'ab'`. This also applies to
`bytearray` subclasses. On free-threaded builds, the copy is protected
by the bytearray's critical section.
The new low-level tests failed before the fix and passed with the
rebuilt CPython 3.14 wheel (32 tests passed locally). The updated
database test checks the returned value with `binary_prefix` enabled and
disabled and is left to CI. Ruff and `git diff --check` passed.
Related discussion in #816.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* `bytearray` values are now handled consistently with `bytes` when
creating SQL literals, including values containing quotes, null bytes,
or backslashes. Subclasses are processed from their byte contents rather
than their string representation.
* **Documentation**
* Clarified how `string_literal` handles byte-like values versus other
objects.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent eef31ea commit 41f49cf
3 files changed
Lines changed: 27 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1194 | 1194 | | |
1195 | 1195 | | |
1196 | 1196 | | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
| 1197 | + | |
| 1198 | + | |
1200 | 1199 | | |
1201 | 1200 | | |
1202 | 1201 | | |
| |||
1221 | 1220 | | |
1222 | 1221 | | |
1223 | 1222 | | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
1224 | 1233 | | |
1225 | 1234 | | |
1226 | 1235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
7 | 18 | | |
8 | 19 | | |
9 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | | - | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
0 commit comments