summaryrefslogtreecommitdiffstats
path: root/vendor/mime
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
commita0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch)
treefc451898ccaf445814e26b46664d78702178101d /vendor/mime
parentAdding debian version 1.71.1+dfsg1-2. (diff)
downloadrustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz
rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/mime')
-rw-r--r--vendor/mime/.cargo-checksum.json2
-rw-r--r--vendor/mime/Cargo.toml20
-rw-r--r--vendor/mime/src/lib.rs9
-rw-r--r--vendor/mime/src/parse.rs93
4 files changed, 113 insertions, 11 deletions
diff --git a/vendor/mime/.cargo-checksum.json b/vendor/mime/.cargo-checksum.json
index 220a47131..f98e49d21 100644
--- a/vendor/mime/.cargo-checksum.json
+++ b/vendor/mime/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"CONTRIBUTING.md":"7a8f1d12eb98bd09c290d31f25b03c71ff78027d9fc468e8782efa7dd3e69f1c","Cargo.toml":"75e36b40187c8edad0baae326a0903b6b462f1acd0d68102a8e4f006b8802041","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"df9cfd06d8a44d9a671eadd39ffd97f166481da015a30f45dfd27886209c5922","README.md":"4ac32f1d6d7e1ac9f89f0a6d7d0cbc26f20ef9defdc7b206ef3a77616f493bbf","benches/cmp.rs":"9deb7c222eb69e7c5160aa82d361d4883792be3b557fbf8f7c807b398ba951a1","benches/fmt.rs":"46ec1e7c7970a3eed84b303309a2395ac16d16534ea691db7f361d0016ef0673","benches/parse.rs":"af2b35fc314e39c7fb3fbe6a77b65e54d0f4bd8956950330700028a98513b7d8","src/lib.rs":"c848e55a49ae4ed6451e94c8c120451b5031ba2ab87170ed389eeb4731679446","src/parse.rs":"cfe11f611901a581245b091942bb28ef2eec57645b981e1699d247f11c9e6fe3"},"package":"2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"} \ No newline at end of file
+{"files":{"CONTRIBUTING.md":"7a8f1d12eb98bd09c290d31f25b03c71ff78027d9fc468e8782efa7dd3e69f1c","Cargo.toml":"fdf8868865cb29fcdc57bf9385cf65b4c1ff7d28ee3f96a6f29a934cc1db2563","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"df9cfd06d8a44d9a671eadd39ffd97f166481da015a30f45dfd27886209c5922","README.md":"4ac32f1d6d7e1ac9f89f0a6d7d0cbc26f20ef9defdc7b206ef3a77616f493bbf","benches/cmp.rs":"9deb7c222eb69e7c5160aa82d361d4883792be3b557fbf8f7c807b398ba951a1","benches/fmt.rs":"46ec1e7c7970a3eed84b303309a2395ac16d16534ea691db7f361d0016ef0673","benches/parse.rs":"af2b35fc314e39c7fb3fbe6a77b65e54d0f4bd8956950330700028a98513b7d8","src/lib.rs":"154cead5ddff82df2b4bda0344bdbbdde5b096fb8e64fce4c624b7d94259694c","src/parse.rs":"3610253295af9780904ae66440f93a9d5d50356392aec839bc71253956b805b9"},"package":"6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"} \ No newline at end of file
diff --git a/vendor/mime/Cargo.toml b/vendor/mime/Cargo.toml
index 1f34190e7..1106da165 100644
--- a/vendor/mime/Cargo.toml
+++ b/vendor/mime/Cargo.toml
@@ -3,21 +3,25 @@
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g., crates.io) dependencies
+# to registry (e.g., crates.io) dependencies.
#
-# If you believe there's an error in this file please file an
-# issue against the rust-lang/cargo repository. If you're
-# editing this file be aware that the upstream Cargo.toml
-# will likely look very different (and much more reasonable)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
[package]
name = "mime"
-version = "0.3.16"
+version = "0.3.17"
authors = ["Sean McArthur <sean@seanmonstar.com>"]
description = "Strongly Typed Mimes"
documentation = "https://docs.rs/mime"
-keywords = ["mime", "media-extensions", "media-types"]
-license = "MIT/Apache-2.0"
+readme = "README.md"
+keywords = [
+ "mime",
+ "media-extensions",
+ "media-types",
+]
+license = "MIT OR Apache-2.0"
repository = "https://github.com/hyperium/mime"
[dependencies]
diff --git a/vendor/mime/src/lib.rs b/vendor/mime/src/lib.rs
index 1f24fb1cf..da1d3c0f6 100644
--- a/vendor/mime/src/lib.rs
+++ b/vendor/mime/src/lib.rs
@@ -23,7 +23,7 @@
//! }
//! ```
-#![doc(html_root_url = "https://docs.rs/mime/0.3.16")]
+#![doc(html_root_url = "https://docs.rs/mime/0.3.17")]
#![deny(warnings)]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
@@ -47,6 +47,13 @@ pub struct Mime {
params: ParamSource,
}
+/// An iterator of parsed mime
+#[derive(Clone, Debug)]
+pub struct MimeIter<'a> {
+ pos: usize,
+ source: &'a str,
+}
+
/// A section of a `Mime`.
///
/// For instance, for the Mime `image/svg+xml`, it contains 3 `Name`s,
diff --git a/vendor/mime/src/parse.rs b/vendor/mime/src/parse.rs
index d55e5494c..20022b775 100644
--- a/vendor/mime/src/parse.rs
+++ b/vendor/mime/src/parse.rs
@@ -5,7 +5,7 @@ use std::fmt;
use std::iter::Enumerate;
use std::str::Bytes;
-use super::{Mime, Source, ParamSource, Indexed, CHARSET, UTF_8};
+use super::{Mime, MimeIter, Source, ParamSource, Indexed, CHARSET, UTF_8};
#[derive(Debug)]
pub enum ParseError {
@@ -49,6 +49,65 @@ impl Error for ParseError {
}
}
+impl<'a> MimeIter<'a> {
+ /// A new iterator over mimes or media types
+ pub fn new(s: &'a str) -> Self {
+ Self {
+ pos: 0,
+ source: s,
+ }
+ }
+}
+
+impl<'a> Iterator for MimeIter<'a> {
+ type Item = Result<Mime, &'a str>;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ let start = self.pos;
+ let len = self.source.bytes().len();
+
+ if start >= len {
+ return None
+ }
+
+ // Try parsing the whole remaining slice, until the end
+ match parse(&self.source[start ..len]) {
+ Ok(value) => {
+ self.pos = len;
+ Some(Ok(value))
+ }
+ Err(ParseError::InvalidToken { pos, .. }) => {
+ // The first token is immediately found to be wrong by `parse`. Skip it
+ if pos == 0 {
+ self.pos += 1;
+ return self.next()
+ }
+ let slice = &self.source[start .. start + pos];
+ // Try parsing the longest slice (until the first invalid token)
+ return match parse(slice) {
+ Ok(mime) => {
+ self.pos = start + pos + 1;
+ Some(Ok(mime))
+ }
+ Err(_) => {
+ if start + pos < len {
+ // Skip this invalid slice,
+ // try parsing the remaining slice in the next iteration
+ self.pos = start + pos;
+ Some(Err(slice))
+ } else {
+ None
+ }
+ }
+ }
+ }
+ // Do not process any other error condition: the slice is malformed and
+ // no character is found to be invalid: a character is missing
+ Err(_) => None,
+ }
+ }
+}
+
pub fn parse(s: &str) -> Result<Mime, ParseError> {
if s == "*/*" {
return Ok(::STAR_STAR);
@@ -361,3 +420,35 @@ fn test_lookup_tables() {
assert_eq!(valid, should, "{:?} ({}) should be {}", i as char, i, should);
}
}
+
+#[test]
+fn test_parse_iterator() {
+ let mut iter = MimeIter::new("application/json, application/json");
+ assert_eq!(iter.next().unwrap().unwrap(), parse("application/json").unwrap());
+ assert_eq!(iter.next().unwrap().unwrap(), parse("application/json").unwrap());
+ assert_eq!(iter.next(), None);
+
+ let mut iter = MimeIter::new("application/json");
+ assert_eq!(iter.next().unwrap().unwrap(), parse("application/json").unwrap());
+ assert_eq!(iter.next(), None);
+
+ let mut iter = MimeIter::new("application/json; ");
+ assert_eq!(iter.next().unwrap().unwrap(), parse("application/json").unwrap());
+ assert_eq!(iter.next(), None);
+}
+
+#[test]
+fn test_parse_iterator_invalid() {
+ let mut iter = MimeIter::new("application/json, invalid, application/json");
+ assert_eq!(iter.next().unwrap().unwrap(), parse("application/json").unwrap());
+ assert_eq!(iter.next().unwrap().unwrap_err(), "invalid");
+ assert_eq!(iter.next().unwrap().unwrap(), parse("application/json").unwrap());
+ assert_eq!(iter.next(), None);
+}
+
+#[test]
+fn test_parse_iterator_all_invalid() {
+ let mut iter = MimeIter::new("application/json, text/html");
+ assert_eq!(iter.next().unwrap().unwrap_err(), "application/json");
+ assert_eq!(iter.next(), None);
+}