GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Handle CTE values case-insensitively · Kludex/python-multipart@b4e682c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • python_multipart
    • multipart.py
  • tests
    • test_multipart.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎python_multipart/multipart.py‎

Copy file name to clipboardExpand all lines: python_multipart/multipart.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,9 @@ def on_headers_finished() -> None:
16651665
# Parse the given Content-Transfer-Encoding to determine what
16661666
# we need to do with the incoming data.
16671667
# TODO: check that we properly handle 8bit / 7bit encoding.
1668-
transfer_encoding = headers.get(b"content-transfer-encoding", b"7bit")
1668+
# RFC 2045 section 6.1: Content-Transfer-Encoding values are case-insensitive.
1669+
# https://www.rfc-editor.org/rfc/rfc2045#section-6.1
1670+
transfer_encoding = headers.get(b"content-transfer-encoding", b"7bit").lower()
16691671

16701672
if transfer_encoding in (b"binary", b"8bit", b"7bit"):
16711673
writer = f_multi
Collapse file

‎tests/test_multipart.py‎

Copy file name to clipboardExpand all lines: tests/test_multipart.py
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,29 @@ def on_file(f: File) -> None:
12301230
f.finalize()
12311231
self.assert_file_data(files[0], b"Test")
12321232

1233+
def test_content_transfer_encoding_is_case_insensitive(self) -> None:
1234+
for content_transfer_encoding in (b"base64", b"BASE64", b"Base64"):
1235+
with self.subTest(content_transfer_encoding=content_transfer_encoding):
1236+
data = (
1237+
b'----boundary\r\nContent-Disposition: form-data; name="file"; filename="test.txt"\r\n'
1238+
b"Content-Type: text/plain\r\n"
1239+
b"Content-Transfer-Encoding: "
1240+
+ content_transfer_encoding
1241+
+ b"\r\n\r\nVGVzdA==\r\n----boundary--\r\n"
1242+
)
1243+
files: list[File] = []
1244+
1245+
f = FormParser(
1246+
"multipart/form-data",
1247+
None,
1248+
files.append,
1249+
boundary="--boundary",
1250+
)
1251+
1252+
f.write(data)
1253+
f.finalize()
1254+
self.assert_file_data(files[0], b"Test")
1255+
12331256
def test_handles_None_fields(self) -> None:
12341257
fields: list[Field] = []
12351258

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.