Skip to content

Commit

Permalink
fix: support complete URLs in <A/> and <Form/> (closes #2076) (#2096
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gbj authored Dec 2, 2023
1 parent ed61ea9 commit 6014a70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion router/src/matching/resolve_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn resolve_path<'a>(
from: Option<&'a str>,
) -> Option<Cow<'a, str>> {
if has_scheme(path) {
None
Some(path.into())
} else {
let base_path = normalize(base, false);
let from_path = from.map(|from| normalize(from, false));
Expand Down
32 changes: 25 additions & 7 deletions router/tests/resolve_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,29 @@ fn preserve_spaces() {
}

#[test]
fn cannot_resolve_if_path_has_scheme() {
assert_eq!(resolve_path("", "http://example.com", None), None);
assert_eq!(resolve_path("", "https://example.com", None), None);
assert_eq!(resolve_path("", "example://google.com", None), None);
assert_eq!(resolve_path("", "tel:+15555555555", None), None);
assert_eq!(resolve_path("", "mailto:[email protected]", None), None);
assert_eq!(resolve_path("", "//relative-protocol", None), None);
fn will_resolve_if_path_has_scheme() {
assert_eq!(
resolve_path("", "http://example.com", None).as_deref(),
Some("http://example.com")
);
assert_eq!(
resolve_path("", "https://example.com", None).as_deref(),
Some("https://example.com")
);
assert_eq!(
resolve_path("", "example://google.com", None).as_deref(),
Some("example://google.com")
);
assert_eq!(
resolve_path("", "tel:+15555555555", None).as_deref(),
Some("tel:+15555555555")
);
assert_eq!(
resolve_path("", "mailto:[email protected]", None).as_deref(),
Some("mailto:[email protected]")
);
assert_eq!(
resolve_path("", "//relative-protocol", None).as_deref(),
Some("//relative-protocol")
);
}

0 comments on commit 6014a70

Please sign in to comment.