Repository navigation
Trim forward slashes from route prefix #395
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,14 +129,22 @@ public ODataOptions AddRouteComponents(string routePrefix, IEdmModel model, Acti | |
| throw Error.ArgumentNull(nameof(model)); | ||
| } | ||
|
|
||
| if (RouteComponents.ContainsKey(routePrefix)) | ||
| if (routePrefix == null) | ||
| { | ||
| throw Error.InvalidOperation(SRResources.ModelPrefixAlreadyUsed, routePrefix); | ||
| throw Error.ArgumentNull(nameof(routePrefix)); | ||
| } | ||
|
|
||
| string sanitizedRoutePrefix = routePrefix.Trim('/'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. If you don't trim the end, an exception is thrown by AspNetCore as mentioned in the description. |
||
|
|
||
| if (RouteComponents.ContainsKey(sanitizedRoutePrefix)) | ||
| { | ||
| throw Error.InvalidOperation(SRResources.ModelPrefixAlreadyUsed, sanitizedRoutePrefix); | ||
| } | ||
|
|
||
|
|
||
| // Consider to use Lazy<IServiceProvider> ? | ||
| IServiceProvider serviceProvider = BuildRouteContainer(model, configureServices); | ||
| RouteComponents[routePrefix] = (model, serviceProvider); | ||
| RouteComponents[sanitizedRoutePrefix] = (model, serviceProvider); | ||
|
gathogojr marked this conversation as resolved.
|
||
| return this; | ||
| } | ||
|
|
||
|
|
||
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.
Don't we have cases where the prefix is null?
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.
We have a case where the prefix is empty (the default case). Not sure about null though.
In any case, you can't add a
nullkey to a dictionary. So I think throwing onnullhere is the right thing to do.