-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find a representation for relative URLs. #10
Comments
It’s been addressed in servo/rust-url#487. URLs can’t be relative, URIs can.
Question: How do URIs interact with substitutions and |
Thanks for bringing that to my attention, I wasn't aware that that was brought up in servo/rust-url. About URLs being relative, as a web dev by day I prefer taking my definitions from the WHATWG URL standard, which effectively deprecates the term URI. Sure, that standard doesn't give a way for browsers to represent relative URLs as a data structure, but it does define them as being URLs. But I'm fine with following the URI RFCs. About the Now, I haven't dug into the docutils code for this, but it seems that after validating a URL they simply store it as text in the |
You’re right, it’s probably easiest to simply create a wrapper type that just validates if we want to construct it with a valid URL: What we need is the ability to represent links. Any link can have a scheme, host, port, path, query and fragment. Neither crate of use http::Uri;
fn main() {
println!("{:?}", "/foo/bar?baz".parse::<Uri>());
// Ok(/foo/bar?baz)
println!("{:?}", "./foo/bar?baz".parse::<Uri>());
// Err(InvalidUri(InvalidFormat))
} |
I put this issue on hold while I tried to figure how to parse standalone hyperlinks (which can't have punctuation at the end) on pest, but now that I'm back to it, I see that the Now, For every other use, we could keep #[derive(Debug,PartialEq,Serialize,Clone)]
#[serde(transparent)]
pub struct Target(String);
impl Target {
pub fn from_absolute_url(input: &str) -> Result<Self, url::ParseError> {
let parse = Url::parse(input)?;
Ok(Target(parse.into_string()))
}
pub fn from_relative_url(input: &str) -> Result<Self, url::ParseError> {
unimplemented!()
}
} |
Yes, you’re right, I didn’t think about compile location specificity of PathBuf or the fact that it could include a query or fragment part. Why would you like to rename it though? |
Well, the name |
Sure, let’s just call it Url then! |
Well, we're already using |
While working on hyperlink references as part of issue #7, I realized that we need a way to represent relative URLs in the RST doctree. The servo/rust-url crate we're using can parse relative URL strings with a base, but can only store absolute URLs. Unfortunately, looking through the first pages of crates.io, nobody seems to have tried to reinvent the wheel in that matter.
For the time being, I'm leaving relative URL references unimplemented. In the meantime I'll fork and play around with the url crate to try and make a version that can represent relative URLs.
The text was updated successfully, but these errors were encountered: