sharry::ids formatting

This commit is contained in:
Jörn-Michael Miehe 2025-07-03 13:07:09 +00:00
parent 46913e93b9
commit fada53044d

View file

@ -54,13 +54,13 @@ impl TryFrom<String> for FileID {
fn try_from(value: String) -> crate::Result<Self> { fn try_from(value: String) -> crate::Result<Self> {
/// Pattern breakdown: /// Pattern breakdown:
/// - `^([^:/?#]+)://` scheme (anything but `:/?#`) + `"://"` /// - `^([^:/?#]+)://` - scheme (anything but `:/?#`) + `"://"`
/// - `([^/?#]+)` authority/host (anything but `/?#`) /// - `([^/?#]+)` - authority/host (anything but `/?#`)
/// - `/api/v2/alias/upload/` literal path segment /// - `/api/v2/alias/upload/` - literal path segment
/// - `([^/]+)` capture SID (one or more non-slash chars) /// - `([^/]+)` - capture SID (one or more non-slash chars)
/// - `/files/tus/` literal path segment /// - `/files/tus/` - literal path segment
/// - `(?P<fid>[^/]+)` capture FID (one or more non-slash chars) /// - `(?P<fid>[^/]+)` - capture FID (one or more non-slash chars)
/// - `$` end of string /// - `$` - end of string
static UPLOAD_URL_RE: LazyLock<Regex> = LazyLock::new(|| { static UPLOAD_URL_RE: LazyLock<Regex> = LazyLock::new(|| {
trace!("compiling UPLOAD_URL_RE"); trace!("compiling UPLOAD_URL_RE");
@ -82,7 +82,7 @@ impl TryFrom<String> for FileID {
Ok(result) Ok(result)
} else { } else {
Err(crate::Error::mismatch( Err(crate::Error::mismatch(
"<proto>://<base>/api/v2/alias/upload/<share>/files/tus/<file>", "<proto>://<host>/api/v2/alias/upload/<share>/files/tus/<file>",
value, value,
)) ))
} }
@ -143,7 +143,7 @@ mod tests {
match err { match err {
crate::Error::Mismatch { expected, actual } => { crate::Error::Mismatch { expected, actual } => {
assert_eq!( assert_eq!(
expected, "<proto>://<base>/api/v2/alias/upload/<share>/files/tus/<file>", expected, "<proto>://<host>/api/v2/alias/upload/<share>/files/tus/<file>",
"Error should output expected format" "Error should output expected format"
); );
assert_eq!(actual, bad.to_string(), "Error should echo back the input"); assert_eq!(actual, bad.to_string(), "Error should echo back the input");