Dirkjan Ochtman 6 лет назад
Родитель
Сommit
c9a7003e29
4 измененных файлов с 9 добавлено и 13 удалено
  1. 2 2
      data-url/src/lib.rs
  2. 1 1
      data-url/src/mime.rs
  3. 5 9
      src/parser.rs
  4. 1 1
      tests/data.rs

+ 2 - 2
data-url/src/lib.rs

@@ -104,7 +104,7 @@ impl<'a> FragmentIdentifier<'a> {
                 // Ignore ASCII tabs or newlines like the URL parser would
                 // Ignore ASCII tabs or newlines like the URL parser would
                 b'\t' | b'\n' | b'\r' => continue,
                 b'\t' | b'\n' | b'\r' => continue,
                 // https://url.spec.whatwg.org/#fragment-percent-encode-set
                 // https://url.spec.whatwg.org/#fragment-percent-encode-set
-                b'\0'...b' ' | b'"' | b'<' | b'>' | b'`' | b'\x7F'...b'\xFF' => {
+                b'\0'..=b' ' | b'"' | b'<' | b'>' | b'`' | b'\x7F'..=b'\xFF' => {
                     percent_encode(byte, &mut string)
                     percent_encode(byte, &mut string)
                 }
                 }
                 // Printable ASCII
                 // Printable ASCII
@@ -183,7 +183,7 @@ fn parse_header(from_colon_to_comma: &str) -> (mime::Mime, bool) {
             b'\t' | b'\n' | b'\r' => continue,
             b'\t' | b'\n' | b'\r' => continue,
 
 
             // https://url.spec.whatwg.org/#c0-control-percent-encode-set
             // https://url.spec.whatwg.org/#c0-control-percent-encode-set
-            b'\0'...b'\x1F' | b'\x7F'...b'\xFF' => percent_encode(byte, &mut string),
+            b'\0'..=b'\x1F' | b'\x7F'..=b'\xFF' => percent_encode(byte, &mut string),
 
 
             // Bytes other than the C0 percent-encode set that are percent-encoded
             // Bytes other than the C0 percent-encode set that are percent-encoded
             // by the URL parser in the query state.
             // by the URL parser in the query state.

+ 1 - 1
data-url/src/mime.rs

@@ -116,7 +116,7 @@ fn contains(parameters: &[(String, String)], name: &str) -> bool {
 fn valid_value(s: &str) -> bool {
 fn valid_value(s: &str) -> bool {
     s.chars().all(|c| {
     s.chars().all(|c| {
         // <https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point>
         // <https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point>
-        matches!(c, '\t' | ' '...'~' | '\u{80}'...'\u{FF}')
+        matches!(c, '\t' | ' '..='~' | '\u{80}'..='\u{FF}')
     }) && !s.is_empty()
     }) && !s.is_empty()
 }
 }
 
 

+ 5 - 9
src/parser.rs

@@ -62,11 +62,11 @@ macro_rules! simple_enum_error {
             __FutureProof,
             __FutureProof,
         }
         }
 
 
-        impl Error for ParseError {
-            fn description(&self) -> &str {
+        impl fmt::Display for ParseError {
+            fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
                 match *self {
                 match *self {
                     $(
                     $(
-                        ParseError::$name => $description,
+                        ParseError::$name => fmt.write_str($description),
                     )+
                     )+
                     ParseError::__FutureProof => {
                     ParseError::__FutureProof => {
                         unreachable!("Don't abuse the FutureProof!");
                         unreachable!("Don't abuse the FutureProof!");
@@ -77,6 +77,8 @@ macro_rules! simple_enum_error {
     }
     }
 }
 }
 
 
+impl Error for ParseError {}
+
 simple_enum_error! {
 simple_enum_error! {
     EmptyHost => "empty host",
     EmptyHost => "empty host",
     IdnaError => "invalid international domain name",
     IdnaError => "invalid international domain name",
@@ -90,12 +92,6 @@ simple_enum_error! {
     Overflow => "URLs more than 4 GB are not supported",
     Overflow => "URLs more than 4 GB are not supported",
 }
 }
 
 
-impl fmt::Display for ParseError {
-    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        fmt::Display::fmt(self.description(), f)
-    }
-}
-
 impl From<::idna::Errors> for ParseError {
 impl From<::idna::Errors> for ParseError {
     fn from(_: ::idna::Errors) -> ParseError {
     fn from(_: ::idna::Errors) -> ParseError {
         ParseError::IdnaError
         ParseError::IdnaError

+ 1 - 1
tests/data.rs

@@ -61,7 +61,7 @@ fn run_parsing(input: &str, base: &str, expected: Result<ExpectedAttributes, ()>
             {
             {
                 $(
                 $(
                     assert_eq!(expected.$attr, quirks::$attr(&url));
                     assert_eq!(expected.$attr, quirks::$attr(&url));
-                )+;
+                )+
             }
             }
         }
         }
     }
     }