Skip to content

[#20] NXRequestAssembler에서 후행 슬래시를 중요시하는 api이면 문제가 발생할 수 있는 예외사항을 해결한다#26

Merged
opficdev merged 3 commits intodevelopfrom
fix/#20-slash
Apr 13, 2026
Merged

[#20] NXRequestAssembler에서 후행 슬래시를 중요시하는 api이면 문제가 발생할 수 있는 예외사항을 해결한다#26
opficdev merged 3 commits intodevelopfrom
fix/#20-slash

Conversation

@opficdev
Copy link
Copy Markdown
Owner

🔗 연관된 이슈

📝 작업 내용

📌 요약

  • 요청 path의 후행 슬래시가 사라질 수 있는 예외를 수정
  • path 병합 로직을 더 단순하게 정리
  • 후행 슬래시 보존 테스트 추가

🔍 상세

  • NXRequestAssembler.mergedPath에서 request path의 trailing slash를 보존하도록 수정
  • base path는 join 시 slash 중복만 방지하도록 처리
  • trimmingCharacters 기반 병합으로 인해 /users//users로 바뀔 수 있던 문제 해결
  • NXRequestBuildLogicTests에 후행 슬래시 보존 케이스 추가

📸 영상 / 이미지 (Optional)

image

@opficdev opficdev self-assigned this Apr 13, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

이번 풀 리퀘스트는 mergedPath 함수를 수정하여 요청 경로의 후행 슬래시를 유지하도록 변경하고 이를 검증하는 테스트를 추가했습니다. 리뷰 결과, requestPath가 /일 때 basePath에 후행 슬래시가 없으면 슬래시가 누락되는 엣지 케이스가 발견되어 로직 개선이 제안되었습니다.

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)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

현재 구현에서는 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)"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 반영

@opficdev opficdev merged commit bd0df30 into develop Apr 13, 2026
4 checks passed
@opficdev opficdev deleted the fix/#20-slash branch April 13, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NXRequestAssembler에서 후행 슬래시를 중요시하는 api이면 문제가 발생할 수 있는 예외사항을 해결한다

1 participant