Commit db83482
committed
Fix unquote IndexError on empty string input
unquote() in _utils.py accesses value[0] and value[-1] without checking
string length first. This raises IndexError when called with an empty
string, which can occur when parsing Digest auth WWW-Authenticate
headers containing parameters with empty unquoted values (e.g. realm=
instead of realm="").
Added a len(value) >= 2 guard and comprehensive test coverage for
empty strings, single characters, quoted values, and unquoted values.
Note: encode#3771 addresses the same issue. This PR adds the regression tests
that are missing there. Happy to close in favor of that PR if tests are
added.
Powered by codepo8 — tribal knowledge extraction identified this as a
guard-level issue: "Check string length before accessing index 0 in
unquote() utilities because empty string inputs cause an IndexError."1 parent b5addb6 commit db83482
2 files changed
+20
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
0 commit comments