diff --git a/actix-router/CHANGES.md b/actix-router/CHANGES.md index 40dcf7e2..77251c21 100644 --- a/actix-router/CHANGES.md +++ b/actix-router/CHANGES.md @@ -1,15 +1,20 @@ # Changes ## 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] * 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] * 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] [#368]: https://github.com/actix/actix-net/pull/368 [#366]: https://github.com/actix/actix-net/pull/366 [#368]: https://github.com/actix/actix-net/pull/368 [#370]: https://github.com/actix/actix-net/pull/370 +[#371]: https://github.com/actix/actix-net/pull/371 ## 0.4.0 - 2021-06-06 diff --git a/actix-router/src/resource.rs b/actix-router/src/resource.rs index fcc271a5..0fad81d0 100644 --- a/actix-router/src/resource.rs +++ b/actix-router/src/resource.rs @@ -448,7 +448,7 @@ impl ResourceDef { }) } - fn parse_param(pattern: &str) -> (PatternElement, String, &str, bool) { + fn parse_param(pattern: &str) -> (PatternElement, String, &str) { const DEFAULT_PATTERN: &str = "[^/]+"; const DEFAULT_PATTERN_TAIL: &str = ".*"; @@ -502,7 +502,7 @@ impl ResourceDef { let regex = format!(r"(?P<{}>{})", &name, &pattern); - (element, regex, unprocessed, tail) + (element, regex, unprocessed) } fn parse( @@ -532,9 +532,9 @@ impl ResourceDef { elements.push(PatternElement::Const(prefix.to_owned())); re.push_str(&escape(prefix)); - let (param_pattern, re_part, rem, tail) = Self::parse_param(rem); + let (param_pattern, re_part, rem) = Self::parse_param(rem); - if tail { + if matches!(param_pattern, PatternElement::Tail(_)) { has_tail_segment = true; } @@ -556,7 +556,7 @@ impl ResourceDef { dyn_elements += 1; } else if !has_tail_segment { - // prevent `Const("")` element from being added after dynamic segments + // prevent `Const("")` element from being added after tail segments elements.push(PatternElement::Const(pattern.to_owned())); re.push_str(&escape(pattern));