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

Use char-based override instead of string in EndsWith #386

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Saturn/Controller.fs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ module Controller =
x.FormattedRouteFunc state (PrintfFormat<_,_,_,_,'Key * string> (route + "/%s")) (fst >> actionHandler)

fun next ctx ->
let hasTrailingSlash = (SubRouting.getNextPartOfPath ctx).LastIndexOf("/") = 0
let hasTrailingSlash = (SubRouting.getNextPartOfPath ctx).LastIndexOf '/' = 0
// If we still have more segments beyond our current segment we'll only match up to the next "/".
// ASP.NET Core decodes everything but "/" characters for Request.Path, so we won't match those by accident here.
(if hasTrailingSlash then routeHandler else segmentRouteHandler) next ctx
Expand Down Expand Up @@ -267,7 +267,7 @@ module Controller =
let trailingSlashHandler : HttpHandler =
fun next ctx ->
let routeHandler = this.RouteFunc state "/"
if ctx.Request.Path.Value.EndsWith("/") then
if ctx.Request.Path.Value.EndsWith '/' then
routeHandler next ctx
else if (SubRouting.getNextPartOfPath ctx = "") then
// TODO this could go away pending discussion about ctx.Request.route modification.
Expand Down Expand Up @@ -360,7 +360,7 @@ module Controller =
choose [
if keyFormat.IsSome then
for (subRoute, sCs) in state.SubControllers do
if not (subRoute.StartsWith("/")) then
if not (subRoute.StartsWith '/') then
failwith (sprintf "Subcontroller route '%s' is not valid, these routes should start with a '/'." subRoute)

let fullRoute = keyFormat.Value + subRoute
Expand Down
4 changes: 2 additions & 2 deletions src/Saturn/ControllerEndpoint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ module Controller =
// yield state.NotFoundHandler.Value

for (subRoute, sCs) in state.SubControllers do
if not (subRoute.StartsWith("/")) then
if not (subRoute.StartsWith '/') then
failwith (sprintf "Subcontroller route '%s' is not valid, these routes should start with a '/'." subRoute)

let fullRoute = keyFormat() + subRoute
Expand All @@ -385,7 +385,7 @@ module Controller =
routef (PrintfFormat<'Key -> obj,_,_,_,'Key> fullRoute) (fun key -> fun nxt ctx -> task {
let v = ctx.Request.Path.Value
let v =
if (v.EndsWith "/") then
if (v.EndsWith '/') then
v.Substring(0, v.Length - 1)
else
v
Expand Down
Loading