|
22 | 22 | import stat
|
23 | 23 | import time
|
24 | 24 |
|
25 |
| -from .rfc7230 import OBS_TEXT, VCHAR |
| 25 | +from .rfc7230 import QUOTED_PAIR_RE, QUOTED_STRING_RE |
26 | 26 |
|
27 | 27 | logger = logging.getLogger("waitress")
|
28 | 28 | queue_logger = logging.getLogger("waitress.queue")
|
@@ -216,40 +216,18 @@ def parse_http_date(d):
|
216 | 216 | return retval
|
217 | 217 |
|
218 | 218 |
|
219 |
| -# RFC 5234 Appendix B.1 "Core Rules": |
220 |
| -# VCHAR = %x21-7E |
221 |
| -# ; visible (printing) characters |
222 |
| -vchar_re = VCHAR |
223 |
| - |
224 |
| -# RFC 7230 Section 3.2.6 "Field Value Components": |
225 |
| -# quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE |
226 |
| -# qdtext = HTAB / SP /%x21 / %x23-5B / %x5D-7E / obs-text |
227 |
| -# obs-text = %x80-FF |
228 |
| -# quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) |
229 |
| -obs_text_re = OBS_TEXT |
230 |
| - |
231 |
| -# The '\\' between \x5b and \x5d is needed to escape \x5d (']') |
232 |
| -qdtext_re = "[\t \x21\x23-\x5b\\\x5d-\x7e" + obs_text_re + "]" |
233 |
| - |
234 |
| -quoted_pair_re = r"\\" + "([\t " + vchar_re + obs_text_re + "])" |
235 |
| -quoted_string_re = '"(?:(?:' + qdtext_re + ")|(?:" + quoted_pair_re + '))*"' |
236 |
| - |
237 |
| -quoted_string = re.compile(quoted_string_re) |
238 |
| -quoted_pair = re.compile(quoted_pair_re) |
239 |
| - |
240 |
| - |
241 | 219 | def undquote(value):
|
242 | 220 | if value.startswith('"') and value.endswith('"'):
|
243 | 221 | # So it claims to be DQUOTE'ed, let's validate that
|
244 |
| - matches = quoted_string.match(value) |
| 222 | + matches = QUOTED_STRING_RE.match(value) |
245 | 223 |
|
246 | 224 | if matches and matches.end() == len(value):
|
247 | 225 | # Remove the DQUOTE's from the value
|
248 | 226 | value = value[1:-1]
|
249 | 227 |
|
250 | 228 | # Remove all backslashes that are followed by a valid vchar or
|
251 | 229 | # obs-text
|
252 |
| - value = quoted_pair.sub(r"\1", value) |
| 230 | + value = QUOTED_PAIR_RE.sub(r"\1", value) |
253 | 231 |
|
254 | 232 | return value
|
255 | 233 | elif not value.startswith('"') and not value.endswith('"'):
|
|
0 commit comments