Skip to content

Commit

Permalink
Special cases to avoid // in combines path.
Browse files Browse the repository at this point in the history
- `merge_paths` does correctly handle the merging of paths with double `/` in the combined path.
- `mount_endpoints_and_merged_docs!` does avoid combined paths with double `/`.
  • Loading branch information
ralpha committed Jul 8, 2022
1 parent ddb07a7 commit 5cb59b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion okapi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
All notable changes to this project will be documented in this file.
This project follows the [Semantic Versioning standard](https://semver.org/).

## Unreleased (2021-xx-xx)
## Unreleased (2022-xx-xx)

### Added

### Changed
- `merge_paths` does correctly handle the merging of paths with double `/` in the combined path.

### Deprecated

Expand Down
10 changes: 9 additions & 1 deletion okapi/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ pub fn merge_paths<S: Display>(
// (if key does not already exists)
for (key, value) in s2 {
let new_key = if key.starts_with('/') {
format!("{}{}", path_prefix, key)
// Check if both the prefix ends with a `/` and key starts with one.
let mut path_prefix = path_prefix.to_string();
if path_prefix.ends_with('/') {
// Avoid a double `/`
path_prefix.pop();
format!("{}{}", path_prefix, key)
} else {
format!("{}{}", path_prefix, key)
}
} else {
log::error!(
"All routes should have a leading '/' but non found in `{}`.",
Expand Down
1 change: 1 addition & 0 deletions rocket-okapi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project follows the [Semantic Versioning standard](https://semver.org/).
### Removed

### Fixed
- `mount_endpoints_and_merged_docs!` does avoid combined paths with double `/`.

### Security

Expand Down

0 comments on commit 5cb59b3

Please sign in to comment.