aide
aide copied to clipboard
Regarding axum update to matchit v0.8
The new matching syntax breaks path_colon_params
in:
https://github.com/tamasfe/aide/blob/7e2d71edf706710ed24241348c689fe89bf7c83a/crates/aide/src/util.rs#L23
This is my, not so good, idea to fix it:
pub fn path_colon_params(s: &str) -> Cow<str> {
// if !s.contains(':') {
// return s.into();
// }
let mut rewritten = String::with_capacity(s.len());
#[derive(Clone, Copy)]
enum State {
None,
// this state is no longer needed?
// WasParam,
WasWildcard,
}
let mut state = State::None;
let chars_pair = s.chars().zip(s.chars().skip(1));
let mut do_escape_next = false;
// look at https://github.com/ibraheemdev/matchit/blob/36e5398589129896c5dad8a6b2580ede59831875/src/escape.rs#L18
for (i, (c, c_next)) in chars_pair.enumerate() {
if do_escape_next {
do_escape_next = false;
continue;
}
if (c == '{' && c_next == '{') || (c == '}' && c_next == '}') {
// This poses a problem when the url have '{' or '}' escaped not sure how and where to handle this
rewritten.push(c);
// skip the next iteration
do_escape_next = true;
continue;
}
match (state, c, c_next) {
(State::None, '{', '*') => {
rewritten.push('{');
state = State::WasWildcard;
}
// This is if, a normal Param is allowed after a wildcard
// (not sure but I think this is a planned feature in the future?)
(State::WasWildcard, _, '}') => {
rewritten.push(c);
rewritten += "+}";
state = State::None;
}
(_, _, _) => {
rewritten.push(c);
}
}
if i == s.len() - 2 {
rewritten.push(c_next);
}
}
rewritten.into()
}
I haven't tested this fully, especially wildcards params, but tested it briefly on:
[patch.crates-io]
axum = { git = 'https://github.com/mladedav/axum.git', rev = "db825f94ec849d39f02f8e9cfc469613680c08f4" }
The new syntax is almost the same except we still need to convert the end if it is {*...} To {...+}.
Code should be: 1: get substring after last / 2: if it starts with {* and ends with } copy string until last / and append contents as { content +} else just return original string.