-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use Matchit to Resolve Per-File Settings #11111
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!!!
{ | ||
Ok(_) => {} | ||
Err(InsertError::Conflict { .. }) => {} | ||
Err(_) => unreachable!("file paths are escaped before being inserted in the router"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was curious about this, and I think I convinced myself that this is correct because all other possible errors (aside from Conflict
) can only occur as a result of characters that the router treats as special. And the escaping done above means that there should be precisely zero special characters in the path.
(It might make sense to add an escape
routine to matchit
. Similar to regex::escape
. That way, you can provide more of a stronger guarantee here.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah after escaping we guarantee that we're inserting a static route, so none of the other errors are possible (barring a bug in matchit
). An escape
function in matchit
is a good idea. I was also considering optimizing the double String::replace
but decided it wasn't worth it for us.
self.settings.push(settings); | ||
|
||
// normalize the path to use `/` separators and escape the '{' and '}' characters, | ||
// which matchit uses for routing parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any other characters that we need to watch out for here? In my previous PR I mentioned colons, which seems irrelevant, but e.g. {*foo}
is a special routing parameter in matchit, right? I assume that's also irrelevant as long as we're escaping the {
and }
characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*
is only considered after a non-escaped {
, so that shouldn't be a problem.
Summary
Continuation of #9444.
matchit
supports escaping routing characters so this change should now be fully compatible.Test Plan
On my machine I'm seeing a ~3% improvement with this change.