-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from DuskSystems/145-ensure-we-use-terms-path…
…-and-route-correctly Ensure 'path' and 'route' terms are used consistently
- Loading branch information
Showing
21 changed files
with
690 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::{error::Error, fmt::Display}; | ||
|
||
/// Errors relating to attempting to decode percent-encoded strings. | ||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum EncodingError { | ||
/// Invalid percent-encoding sequence encountered. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust | ||
/// use wayfind::errors::EncodingError; | ||
/// | ||
/// let error = EncodingError::InvalidEncoding { | ||
/// input: "/hello%GGworld".to_string(), | ||
/// position: 6, | ||
/// character: [b'%', b'G', b'G'], | ||
/// }; | ||
/// | ||
/// let display = " | ||
/// invalid percent-encoding | ||
/// | ||
/// Input: /hello%GGworld | ||
/// ^^^ | ||
/// | ||
/// Expected: '%' followed by two hexadecimal digits (a-F, 0-9) | ||
/// Found: '%GG' | ||
/// "; | ||
/// | ||
/// assert_eq!(error.to_string(), display.trim()); | ||
/// ``` | ||
InvalidEncoding { | ||
/// The unaltered input string. | ||
input: String, | ||
/// The position in the input where the invalid encoding was found. | ||
position: usize, | ||
/// The invalid character sequence. | ||
character: [u8; 3], | ||
}, | ||
} | ||
|
||
impl Error for EncodingError {} | ||
|
||
impl Display for EncodingError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::InvalidEncoding { | ||
input, | ||
position, | ||
character, | ||
} => { | ||
let character = String::from_utf8_lossy(character); | ||
let arrow = " ".repeat(*position) + "^^^"; | ||
|
||
write!( | ||
f, | ||
"invalid percent-encoding | ||
Input: {input} | ||
{arrow} | ||
Expected: '%' followed by two hexadecimal digits (a-F, 0-9) | ||
Found: '{character}'", | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,26 @@ | ||
use std::{error::Error, fmt::Display}; | ||
|
||
/// Errors relating to attempting to decode and validate path. | ||
use super::EncodingError; | ||
|
||
/// Errors relating to attempting to decode and validate path. | ||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum PathError { | ||
/// Invalid percent-encoding sequence encountered. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust | ||
/// use wayfind::errors::PathError; | ||
/// | ||
/// let error = PathError::InvalidEncoding { | ||
/// input: "/hello%GGworld".to_string(), | ||
/// position: 6, | ||
/// character: [b'%', b'G', b'G'], | ||
/// }; | ||
/// | ||
/// let display = " | ||
/// invalid percent-encoding | ||
/// | ||
/// Input: /hello%GGworld | ||
/// ^^^ | ||
/// | ||
/// Expected: '%' followed by two hexadecimal digits (a-F, 0-9) | ||
/// Found: '%GG' | ||
/// "; | ||
/// | ||
/// assert_eq!(error.to_string(), display.trim()); | ||
/// ``` | ||
InvalidEncoding { | ||
/// The unaltered input string. | ||
input: String, | ||
/// The position in the input where the invalid encoding was found. | ||
position: usize, | ||
/// The invalid character sequence. | ||
character: [u8; 3], | ||
}, | ||
/// A [`EncodingError`] that occurred during the decoding. | ||
EncodingError(EncodingError), | ||
} | ||
|
||
impl Error for PathError {} | ||
|
||
impl Display for PathError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::InvalidEncoding { | ||
input, | ||
position, | ||
character, | ||
} => { | ||
let character = String::from_utf8_lossy(character); | ||
let arrow = " ".repeat(*position) + "^^^"; | ||
|
||
write!( | ||
f, | ||
"invalid percent-encoding | ||
Input: {input} | ||
{arrow} | ||
Expected: '%' followed by two hexadecimal digits (a-F, 0-9) | ||
Found: '{character}'", | ||
) | ||
} | ||
Self::EncodingError(error) => error.fmt(f), | ||
} | ||
} | ||
} | ||
|
||
impl From<EncodingError> for PathError { | ||
fn from(error: EncodingError) -> Self { | ||
Self::EncodingError(error) | ||
} | ||
} |
Oops, something went wrong.