django/tests/utils_tests
Alex Vandiver 8914b571eb Fixed #36023 -- Handled controls chars in content_disposition_header.
To use the simple `filename="..."` form, the value must conform to the
official grammar from RFC6266[^1]:

    filename-parm       = "filename" "=" value
    value               = <value, defined in [RFC2616], Section 3.6>
                        ; token | quoted-string

The `quoted-string` definition comes from RFC 9110[^2]:

```
    quoted-string  = DQUOTE *( qdtext / quoted-pair ) DQUOTE
    qdtext         = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text

The backslash octet ("\") can be used as a single-octet quoting
mechanism within quoted-string and comment constructs. Recipients that
process the value of a quoted-string MUST handle a quoted-pair as if
it were replaced by the octet following the backslash.

    quoted-pair    = "\" ( HTAB / SP / VCHAR / obs-text )

A sender SHOULD NOT generate a quoted-pair in a quoted-string except
where necessary to quote DQUOTE and backslash octets occurring within
that string.
```

That is, quoted strings are able to express horizontal tabs, space
characters, and everything in the range from 0x21 to 0x7e, expect for
0x22 (`"`) and 0x5C (`\`), which can still be expressed but must be
escaped with their own `\`.

We ignore the case of `obs-text`, which is defined as the range
0x80-0xFF, since its presence is there for permissive parsing of
accidental high-bit characters, and it should not be generated by
conforming implementations.

Transform this character range into a regex and apply it in addition
to the "is ASCII" check.  This ensures that all simple filenames are
expressed in the simple format, and that all filenames with newlines
and other control characters are properly expressed with the
percent-encoded `filename*=...`form.

[^1]: https://datatracker.ietf.org/doc/html/rfc6266#section-4.1
[^2]: https://datatracker.ietf.org/doc/html/rfc9110#name-quoted-strings
2025-01-07 09:22:09 +01:00
..
archives
eggs
files
test_module
traversal_archives
__init__.py
deconstructible_classes.py
models.py
test_archive.py Used addCleanup() in tests where appropriate. 2023-12-31 10:01:31 +01:00
test_autoreload.py Used addCleanup() in tests where appropriate. 2023-12-31 10:01:31 +01:00
test_choices.py Refs #34899 -- Extracted Field.flatchoices to flatten_choices helper function. 2023-10-23 13:44:23 -03:00
test_connection.py
test_crypto.py Refs #33476 -- Applied Black's 2023 stable style. 2023-02-01 11:04:38 +01:00
test_datastructures.py Applied Black's 2024 stable style. 2024-01-26 12:45:07 +01:00
test_dateformat.py Used enterClassContext() where appropriate. 2024-01-04 05:55:29 +01:00
test_dateparse.py Fixed #35097 -- Tested parse_datetime() with bare date. 2024-01-09 14:08:03 -03:00
test_deconstruct.py
test_decorators.py
test_duration.py
test_encoding.py Refs #34986 -- Fixed some test assertions for PyPy. 2023-11-28 06:19:38 +01:00
test_feedgenerator.py Fixed #12978 -- Added support for RSS feed stylesheets. 2024-06-18 17:25:43 +02:00
test_functional.py Allowed custom formatting of lazy() objects. 2023-06-12 06:09:20 +02:00
test_hashable.py
test_html.py Fixed #36012 -- Made mailto punctuation percent-encoded in Urlizer. 2024-12-17 10:18:48 +01:00
test_http.py Fixed #36023 -- Handled controls chars in content_disposition_header. 2025-01-07 09:22:09 +01:00
test_inspect.py
test_ipv6.py Updated documentation and comments for RFC updates. 2022-11-10 13:52:17 +01:00
test_itercompat.py Fixed #35666 -- Documented stacklevel usage and testing, and adjusted test suite accordingly. 2024-08-28 11:44:05 -03:00
test_lazyobject.py Fixed utils_tests.test_lazyobject.SimpleLazyObjectPickleTestCase. 2023-08-20 16:09:07 +02:00
test_lorem_ipsum.py
test_module_loading.py Fixed #34233 -- Dropped support for Python 3.8 and 3.9. 2023-01-18 09:46:01 +01:00
test_no_submodule.py
test_numberformat.py Refs #34000 -- Optimized handling None values in numberformat.format(). 2022-09-12 13:02:50 +02:00
test_os_utils.py
test_regex_helper.py
test_safestring.py Fixed #35648 -- Raised NotImplementedError in SafeString.__add__ for non-string RHS. 2024-08-12 14:25:05 -03:00
test_simplelazyobject.py
test_termcolors.py
test_text.py Refs CVE-2024-27351 -- Forwardported release notes and tests. 2024-03-04 08:22:00 +01:00
test_timesince.py Refs #34483 -- Fixed timesince()/timeuntil() with timezone-aware dates on different days and interval less than 1 day. 2023-04-14 17:41:03 +02:00
test_timezone.py Fixed #34233 -- Dropped support for Python 3.8 and 3.9. 2023-01-18 09:46:01 +01:00
test_tree.py
utils.py