-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
72 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -36,22 +36,14 @@ impl Base { | |
} | ||
} | ||
|
||
pub(crate) fn from_source(source: &InputSource) -> Option<ada_url::Url> { | ||
pub(crate) fn from_source(source: &InputSource) -> Option<Url> { | ||
match &source { | ||
InputSource::RemoteUrl(url) => { | ||
// TODO: This should be refactored. | ||
// Cases like https://user:[email protected] are not handled | ||
// We can probably use the original URL and just replace the | ||
// path component in the caller of this function | ||
if let Some(port) = url.port() { | ||
Url::parse( | ||
&format!("{}://{}:{port}", url.scheme(), url.host_str()?), | ||
None, | ||
) | ||
.ok() | ||
} else { | ||
Url::parse(&format!("{}://{}", url.scheme(), url.host_str()?), None).ok() | ||
} | ||
Url::parse(&format!("{}//{}", url.protocol(), url.host()), None).ok() | ||
} | ||
// other inputs do not have a URL to extract a base | ||
_ => None, | ||
|
@@ -66,7 +58,7 @@ impl TryFrom<&str> for Base { | |
if let Ok(url) = Url::parse(value, None) { | ||
// Cannot be a base | ||
// Character after scheme should be '/' | ||
if url.href().chars().nth(url.protocol().len()) == Some('/') { | ||
if url.href().chars().nth(url.protocol().len()) != Some('/') { | ||
return Err(ErrorKind::InvalidBase( | ||
value.to_string(), | ||
"The given URL cannot be a base".to_string(), | ||
|
@@ -127,7 +119,7 @@ mod test_base { | |
), | ||
] { | ||
let url = Url::parse(url, None).unwrap(); | ||
let source = InputSource::String(url.href().to_string()); | ||
let source = InputSource::RemoteUrl(Box::from(url)); | ||
let base = Base::from_source(&source); | ||
let expected = Url::parse(expected, None).unwrap(); | ||
assert_eq!(base, Some(expected)); | ||
|
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