pub enum Filename<'a> {
Plain(Word<'a>),
Ext(ExtValue<'a>),
}Expand description
A file name from Content-Disposition or a Link title.
Variants§
Plain(Word<'a>)
The filename (or title) parameter.
Ext(ExtValue<'a>)
The filename* (or title*) parameter.
Implementations§
Source§impl Filename<'_>
impl Filename<'_>
Sourcepub fn max_decoded_len(&self) -> usize
pub fn max_decoded_len(&self) -> usize
An upper bound on the length the decode functions write.
Sourcepub fn decode_into<'b>(&self, out: &'b mut [u8]) -> Result<&'b str, ParseError>
pub fn decode_into<'b>(&self, out: &'b mut [u8]) -> Result<&'b str, ParseError>
Decodes into out: the unescaped filename as UTF-8, or the decoded
filename*. Separators (/, \) pass through; see
has_path_separator.
§Errors
ErrorKind::InvalidUtf8, ErrorKind::ControlInDecoded,
ErrorKind::BufferTooSmall. Nothing is written on error.
Sourcepub fn decode_percent_into<'b>(
&self,
out: &'b mut [u8],
) -> Result<&'b str, ParseError>
pub fn decode_percent_into<'b>( &self, out: &'b mut [u8], ) -> Result<&'b str, ParseError>
As decode_into, and %XX in a plain
filename is decoded too (RFC 7578 section 2 percent-encoded file
names).
§Errors
As decode_into, and
ErrorKind::InvalidPercentEncoding.
§Examples
let cd = parse_net::parse_content_disposition(b"form-data; name=f; filename=\"caf%C3%A9.txt\"")?;
let mut buf = [0u8; 32];
assert_eq!(cd.filename().expect("present").decode_percent_into(&mut buf)?, "caf\u{e9}.txt");Sourcepub fn has_path_separator(&self) -> bool
pub fn has_path_separator(&self) -> bool
Whether the decoded name contains / or \ (in a plain name, also
after percent-decoding). The file-name policy belongs to the caller
(path-lib, customs-sec).
Sourcepub fn has_bidi_control(&self) -> bool
pub fn has_bidi_control(&self) -> bool
Whether the decoded name contains a bidirectional control character
(U+202A to U+202E, U+2066 to U+2069), used to disguise an extension
(exe.txt shown for txt.exe). Reported, not refused.
§Examples
let cd = parse_net::parse_content_disposition(b"attachment; filename*=UTF-8''invoice%E2%80%AEfdp.exe")?;
assert!(cd.filename().expect("present").has_bidi_control());