[#20] NXRequestAssembler에서 후행 슬래시를 중요시하는 api이면 문제가 발생할 수 있는 예외사항을 해결한다#26
Merged
[#20] NXRequestAssembler에서 후행 슬래시를 중요시하는 api이면 문제가 발생할 수 있는 예외사항을 해결한다#26
Conversation
Comment on lines
+52
to
+67
| let normalizedBasePath = basePath.isEmpty ? "/" : (basePath.hasPrefix("/") ? basePath : "/\(basePath)") | ||
| let normalizedRequestPath = requestPath.hasPrefix("/") ? String(requestPath.dropFirst()) : requestPath | ||
|
|
||
| if trimmedBasePath.isEmpty { | ||
| return "/\(trimmedRequestPath)" | ||
| guard !normalizedRequestPath.isEmpty else { | ||
| return normalizedBasePath | ||
| } | ||
|
|
||
| if trimmedRequestPath.isEmpty { | ||
| return "/\(trimmedBasePath)" | ||
| if normalizedBasePath == "/" { | ||
| return "/\(normalizedRequestPath)" | ||
| } | ||
|
|
||
| return "/\(trimmedBasePath)/\(trimmedRequestPath)" | ||
| if normalizedBasePath.hasSuffix("/") { | ||
| return "\(normalizedBasePath)\(normalizedRequestPath)" | ||
| } | ||
|
|
||
| return "\(normalizedBasePath)/\(normalizedRequestPath)" |
There was a problem hiding this comment.
현재 구현에서는 requestPath가 /인 경우 normalizedRequestPath가 빈 문자열이 되어 guard 문에서 normalizedBasePath를 그대로 반환합니다. 이로 인해 basePath에 후행 슬래시가 없는 경우(예: /api), requestPath로 전달한 /가 무시되어 /api/가 아닌 /api가 반환되는 문제가 발생합니다. 후행 슬래시 보존이라는 PR의 목적에 부합하도록 로직을 개선하고 가독성을 높이는 것을 권장합니다.
let normalizedBasePath = basePath.hasPrefix("/") ? basePath : "/\(basePath)"
if requestPath.isEmpty {
return normalizedBasePath
}
let normalizedRequestPath = requestPath.hasPrefix("/") ? String(requestPath.dropFirst()) : requestPath
let separator = normalizedBasePath.hasSuffix("/") ? "" : "/"
return "\(normalizedBasePath)\(separator)\(normalizedRequestPath)"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 연관된 이슈
📝 작업 내용
📌 요약
🔍 상세
NXRequestAssembler.mergedPath에서 request path의 trailing slash를 보존하도록 수정trimmingCharacters기반 병합으로 인해/users/가/users로 바뀔 수 있던 문제 해결NXRequestBuildLogicTests에 후행 슬래시 보존 케이스 추가📸 영상 / 이미지 (Optional)