diff --git a/actix-router/CHANGES.md b/actix-router/CHANGES.md index 24b8235c..6312e22d 100644 --- a/actix-router/CHANGES.md +++ b/actix-router/CHANGES.md @@ -3,19 +3,19 @@ ## Unreleased - 2021-xx-xx * Resource definitions with unnamed tail segments now correctly interpolate the tail when constructed from an iterator. [#371] * Introduce `ResourceDef::resource_path_from_map_with_tail` method to allow building paths in the presence of unnamed tail segments. [#371] +* Introduce `ResourceDef::pattern_iter` to get an iterator over all patterns in a multi-pattern resource. [#373] * Fix segment interpolation leaving `Path` in unintended state after matching. [#368] * Path tail pattern now works as expected after a dynamic segment (e.g. `/user/{uid}/*`). [#366] -* Fixed a bug where, in multi-patterns, static patterns are interpreted as regex. [#366] +* Fixed a bug in multi-patterns where static patterns are interpreted as regex. [#366] * Re-work `IntoPatterns` trait. [#372] * Rename `Path::{len => segment_count}` to be more descriptive of it's purpose. [#370] -* Alias `ResourceDef::{resource_path => resource_path_from_iter}` pending eventual deprecation. [#371] -* Alias `ResourceDef::{resource_path_named => resource_path_from_map}` pending eventual deprecation. [#371] +* Rename `ResourceDef::{resource_path => resource_path_from_iter}`. [#371] +* Rename `ResourceDef::{resource_path_named => resource_path_from_map}`. [#371] +* Rename `ResourceDef::{match_path => is_path_match}`. [#373] +* Rename `ResourceDef::{match_path_checked => is_path_match_fn}`. [#373] * Remove `ResourceDef::name_mut` and introduce `ResourceDef::set_name`. [#373] * Return type of `ResourceDef::name` is now `Option<&str>`. [#373] * Return type of `ResourceDef::pattern` is now `Option<&str>`. [#373] -* Introduce `ResourceDef::pattern_iter` to get an iterator over all patterns in a multi-pattern resource. [#373] -* Rename `ResourceDef::{match_path => is_path_match}`. [#373] -* Rename `ResourceDef::{match_path_checked => is_path_match_fn}`. [#373] [#368]: https://github.com/actix/actix-net/pull/368 [#366]: https://github.com/actix/actix-net/pull/366 diff --git a/actix-router/src/path.rs b/actix-router/src/path.rs index b937665c..38931c35 100644 --- a/actix-router/src/path.rs +++ b/actix-router/src/path.rs @@ -122,7 +122,7 @@ impl Path { /// Get matched parameter by name without type conversion pub fn get(&self, key: &str) -> Option<&str> { profile_method!(get); - + for item in self.segments.iter() { if key == item.0 { return match item.1 { @@ -150,7 +150,7 @@ impl Path { /// If keyed parameter is not available empty string is used as default value. pub fn query(&self, key: &str) -> &str { profile_method!(query); - + if let Some(s) = self.get(key) { s } else { diff --git a/actix-router/src/resource.rs b/actix-router/src/resource.rs index 85434cc7..e03c0fe4 100644 --- a/actix-router/src/resource.rs +++ b/actix-router/src/resource.rs @@ -674,17 +674,6 @@ impl ResourceDef { self.build_resource_path(path, |_| values.next()) } - // intentionally not deprecated yet - #[doc(hidden)] - pub fn resource_path(&self, path: &mut String, values: &mut U) -> bool - where - U: Iterator, - I: AsRef, - { - profile_method!(build_resource_path); - self.resource_path_from_iter(path, values) - } - /// Assembles resource path from map of dynamic segment values. /// /// Returns `true` on success. @@ -708,21 +697,6 @@ impl ResourceDef { }) } - // intentionally not deprecated yet - #[doc(hidden)] - pub fn resource_path_named( - &self, - path: &mut String, - values: &HashMap, - ) -> bool - where - K: Borrow + Eq + Hash, - V: AsRef, - S: BuildHasher, - { - self.resource_path_from_map(path, values) - } - /// Assembles resource path from map of dynamic segment values, allowing tail segments to /// be appended. /// @@ -1278,6 +1252,7 @@ mod tests { assert_eq!(path.unprocessed(), "subpath1/subpath2/index.html"); let resource = ResourceDef::prefix("/user"); + // input string shorter than prefix assert!(resource.is_prefix_match("/foo").is_none()); }