Repository navigation
v0.18.0
Changed
Parsing and building follow RFC 2046 §5.1 and RFC 7578 more closely. Some input that was accepted before is now rejected, so code that builds parts from user input may need to handle more errors.
new_filewrites a non-ASCII filename as UTF-8 in the quotedfilenameparameter, as browsers do, and no longer adds afilename*parameter or an ASCII fallback with_. RFC 7578 §4.2 forbidsfilename*in form data.parsestill readsfilename*when a client sends it.encodereturnsInvalidBoundary(boundary)when a header or body line of a part starts with--and the boundary, which RFC 2046 §5.1.1 forbids and a receiver would read as a delimiter.stream.encodegives the same error item when it reaches such a line, even across chunks, andencode_formdraws a new boundary.- A header name must be printable ASCII without spaces or
:(RFC 5322 §3.6.8).new_partreturnsInvalidHeaderNameandparsereturnsInvalidHeaderfor one that is not, such asContent-Disposition :with a space before the colon, which another parser could read asContent-Disposition. parseandstream.parseunfold a header line that starts with a space or tab into the line before it (RFC 5322 §2.2.3), instead of returningInvalidHeader. A continuation line with no header before it is stillInvalidHeader.- A parameter given twice, ignoring case, makes a
Content-TypeInvalidContentType(RFC 6838 §4.3) and aContent-DispositionInvalidContentDisposition(RFC 6266 §4.1). Before, the first one was used, soboundary=a; boundary=borname="a"; name="admin"could be read differently by another parser. - Both headers accept an empty parameter (
;;or a trailing;, RFC 9110 §5.6.6).Content-Dispositionalso accepts whitespace around=(RFC 6266 §4.1); aContent-Typedoes not (RFC 9110). - A quoted
boundarythat escapes a control character isInvalidContentType, as a quotedContent-Dispositionvalue already wasInvalidQuotedPair. - A
filename*orname*that cannot be decoded, because it holds a character outside RFC 5987attr-charand%escapes, names another charset, or decodes to CR, LF or NUL, is ignored and the plainfilenameornameis used (RFC 6266 §4.3). Before, it made the whole body fail withInvalidContentDisposition, and characters such as a space were accepted. parsereads the body up tomax_body_bytesand reports the first problem in it, asstream.parsedoes. A body over the limit with a bad header before the limit now fails with the header error instead ofBodyTooLarge.- The error variants that hold a
Stringhave labels, like the others:InvalidContentType(content_type:),InvalidBoundary(boundary:),UnsupportedMediaType(media_type:),InvalidHeader(line:),InvalidContentDisposition(value:),InvalidQuotedPair(value:)andDisallowedContentType(content_type:). Positional patterns still compile. - The test suite uses metamon 0.14.0.
Fixed
- A part whose blank line is also the line break of the next delimiter, as in
--b\r\n\r\n--b--, has an empty body. Before, its body was the line break. --b --(padding before the closing--) is no longer read as the closing delimiter. RFC 2046 allows padding only after the--.parseandstream.parsereject a header line that holds a bare CR or NUL withInvalidHeader. Before, the part kept it, andencodewrote it back out, where a receiver that ends lines at CR would see an extra header.- On JavaScript, a
Content-DispositionorContent-Typewith a few thousand parameters, afilename*with thousands of%escapes, or a header value with thousands of trailing spaces overflowed the stack. The repeated-parameter check also stays linear, so such a value costs milliseconds. stream.parsegave different results for the same input depending on how it was split when a limit was reached: a chunk that crossedmax_body_byteshid a header or part error before the limit, and transport padding after a delimiter counted towardsmax_part_bytes.parsereturnedUnexpectedEndOfInputwherestream.parsereturnedPartTooLargefor an unfinished part over the limit. Both now give the same result however the input is split.
Install
gleam add multipartkitSee HexDocs for the API
reference.