Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deserializing paths to sequences for multi-component (eg. tail) matches #3432

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

maartendeprez
Copy link

@maartendeprez maartendeprez commented Jul 18, 2024

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

When extracting path parameters with a custom regex matching multiple path components (eg. "/path/to/{tail:.*}"), there is currently no way to percent-decode the components individually. This pull request changes that by adding support for sequences in the path deserializer. When deserializing the path into a Vec or a tuple, the path segment is first split on slashes, then individual path components are percent-decoded and offered to the deserializing type. Empty path components are ignored.

Since the parameter deserializer did not previously support deserializing to a sequence, I expect this to be fully backward compatible.

/// }
///
/// // extract `Tail` from a path using serde
/// #[get("/path/to/{tail:.*}")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please can we use the suggested syntax for tail matches in the tests and docs
https://docs.rs/actix-router/latest/actix_router/struct.ResourceDef.html#tail-segments

Suggested change
/// #[get("/path/to/{tail:.*}")]
/// #[get("/path/to/{tail}*")]

@@ -5,6 +5,7 @@
## 0.5.3

- Add `unicode` crate feature (on-by-default) to switch between `regex` and `regex-lite` as a trade-off between full unicode support and binary size.
- Add support for extracting multi-component path params into a sequence (Vec, tuple, ...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to unreleased section

@maartendeprez
Copy link
Author

Updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants