Description
I'd like to request your thoughts on the following feature idea.
Context
In my ActivityPub web application, I'm parsing untrusted user input as URLs and then storing them in the database. To reject URLs that are too long, I use the garde crate:
// The form accepted by HTTP endpoints
#[derive(Validate)]
pub struct CreateActivityPubUser {
#[garde(length(max = 2048), url)]
pub activity_pub_id: String,
// ...
}
The Problem
To make working with form structs more ergonomic, I'd like to use an Url
value instead of a String
. However, there's no way to inspect an Url
and check its length, making it impossible to validate an already parsed Url
.
Ideal Solution
Provide method on Url
structs to obtain some measure of their length. The concrete unit being counted is not important, as long as it allows determining whether an Url
exceeds some upper bound.
This would allow garde
and other crates to validate Url
structs directly:
// The form accepted by HTTP endpoints
#[derive(Validate)]
pub struct CreateActivityPubUser {
#[garde(length(max = 2048))]
pub activity_pub_id: Url,
// ...
}
Alternative Solutions
Either a method to truncate a given URL to a certain length, or a way to restrict URL length while parsing would work as well.
Activity