♻️ (response): Renombra Waypoint::as_str a as_deref
This commit is contained in:
parent
e24b9ab9de
commit
d8f82ea1d2
2 changed files with 6 additions and 6 deletions
|
|
@ -75,7 +75,7 @@ impl Waypoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Devuelve la URL de destino, si se proporcionó una y es una ruta local válida.
|
/// Devuelve la URL de destino, si se proporcionó una y es una ruta local válida.
|
||||||
pub fn as_str(&self) -> Option<&str> {
|
pub fn as_deref(&self) -> Option<&str> {
|
||||||
self.waypoint.as_deref()
|
self.waypoint.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ impl Waypoint {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn append_to(&self, route: impl Into<RoutePath>) -> RoutePath {
|
pub fn append_to(&self, route: impl Into<RoutePath>) -> RoutePath {
|
||||||
let mut route = route.into();
|
let mut route = route.into();
|
||||||
if let Some(d) = self.as_str() {
|
if let Some(d) = self.as_deref() {
|
||||||
route.alter_param("waypoint", d);
|
route.alter_param("waypoint", d);
|
||||||
}
|
}
|
||||||
route
|
route
|
||||||
|
|
@ -144,7 +144,7 @@ impl Waypoint {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn or(&self, fallback: impl Into<RoutePath>) -> RoutePath {
|
pub fn or(&self, fallback: impl Into<RoutePath>) -> RoutePath {
|
||||||
match self.as_str() {
|
match self.as_deref() {
|
||||||
Some(d) => RoutePath::new(d.to_owned()),
|
Some(d) => RoutePath::new(d.to_owned()),
|
||||||
None => fallback.into(),
|
None => fallback.into(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use pagetop::prelude::*;
|
||||||
async fn waypoint_accepts_local_paths() {
|
async fn waypoint_accepts_local_paths() {
|
||||||
for path in ["/", "/admin/users", "/admin/users?page=2"] {
|
for path in ["/", "/admin/users", "/admin/users?page=2"] {
|
||||||
let w = Waypoint::from(path.to_owned());
|
let w = Waypoint::from(path.to_owned());
|
||||||
assert_eq!(w.as_str(), Some(path));
|
assert_eq!(w.as_deref(), Some(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ async fn waypoint_rejects_open_redirect_targets() {
|
||||||
"javascript:alert(1)",
|
"javascript:alert(1)",
|
||||||
] {
|
] {
|
||||||
let w = Waypoint::from(target.to_owned());
|
let w = Waypoint::from(target.to_owned());
|
||||||
assert_eq!(w.as_str(), None, "expected {target:?} to be rejected");
|
assert_eq!(w.as_deref(), None, "expected {target:?} to be rejected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ async fn waypoint_deserialize_rejects_open_redirect_targets() {
|
||||||
// Reproduces the real entry point (`web::Query<Waypoint>`): the value arrives via
|
// Reproduces the real entry point (`web::Query<Waypoint>`): the value arrives via
|
||||||
// deserialization, not through `Waypoint::from(String)` as in the previous test.
|
// deserialization, not through `Waypoint::from(String)` as in the previous test.
|
||||||
let w: Waypoint = serde_json::from_str(r#"{"waypoint":"https://evil.example"}"#).unwrap();
|
let w: Waypoint = serde_json::from_str(r#"{"waypoint":"https://evil.example"}"#).unwrap();
|
||||||
assert_eq!(w.as_str(), None);
|
assert_eq!(w.as_deref(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
// **< Waypoint::or() >*****************************************************************************
|
// **< Waypoint::or() >*****************************************************************************
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue