From 93bb6b2e4aa1f7daa498332671798914a23c81a8 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 13 Mar 2025 00:06:02 +0100 Subject: [PATCH] Fixed an issue when routing empty "uriResource" inside the "handle(_: context: next: )" function for the DocCMiddleware middleware in the library target. --- Library/Sources/Internal/Middlewares/DocCMiddleware.swift | 6 +++++- .../Cases/Internal/Middlewares/DoccMiddlewareTests.swift | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Library/Sources/Internal/Middlewares/DocCMiddleware.swift b/Library/Sources/Internal/Middlewares/DocCMiddleware.swift index 8400241..db9d8fb 100644 --- a/Library/Sources/Internal/Middlewares/DocCMiddleware.swift +++ b/Library/Sources/Internal/Middlewares/DocCMiddleware.swift @@ -70,7 +70,11 @@ struct DocCMiddleware< // rule #5: Redirects URI resources with `/` to `/documentation`. if uriResource == .forwardSlash { - return .redirect(to: String(format: .Format.Path.documentation, uriPath)) + return if uriPath.hasSuffix(.forwardSlash) { + .redirect(to: String(format: .Format.Path.documentation, uriPath)) + } else { + .redirect(to: String(format: .Format.Path.forwardSlash, uriPath)) + } } for staticFile in StaticFile.allCases { diff --git a/Test/Sources/Cases/Internal/Middlewares/DoccMiddlewareTests.swift b/Test/Sources/Cases/Internal/Middlewares/DoccMiddlewareTests.swift index 2371d96..bffecdd 100644 --- a/Test/Sources/Cases/Internal/Middlewares/DoccMiddlewareTests.swift +++ b/Test/Sources/Cases/Internal/Middlewares/DoccMiddlewareTests.swift @@ -112,6 +112,7 @@ private extension Collection where Element == String { static var pathsRedirect: [String] {[ + "/archives/SomeArchive/", "/archives/SomeArchive/documentation", "/archives/SomeArchive/documentation/", "/archives/SomeArchive/tutorials/", @@ -142,6 +143,7 @@ private extension Collection where Element == String { ]} static var urisRedirect: [String] {[ + "/archives/SomeArchive", "/archives/SomeArchive/", "/archives/SomeArchive/documentation", "/archives/SomeArchive/tutorials",