fix: reactive 예외 핸들러 JSON 응답 UTF-8 인코딩 명시#256
Open
z3rotig4r wants to merge 1 commit into
Open
Conversation
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.
변경 이유
reactive 모듈 전역 예외 핸들러(
EgovExceptionHandler)가 JSON 에러 응답 본문을 플랫폼 기본 charset으로 직렬화합니다.handlerResponse(EgovExceptionHandler.java:88)는JSONObject.toJSONString(...).getBytes()로 본문을 인코딩합니다. 인자 없는getBytes()는 JVM 기본 charset(file.encoding)을 사용하므로, 기본값이 UTF-8이 아닌 환경(예: MS949 한글 Windows 서버)에서는 응답 바이트가 깨집니다.application/json(L81)으로 charset이 명시되지 않습니다. JSON은 RFC 8259상 UTF-8이어야 합니다.EgovServiceException.getMessage()를 그대로 본문에 담습니다. 애플리케이션이 한글 예외 메시지를 던지면 클라이언트가 받는 에러 메시지가 깨질 수 있습니다.변경 내용
EgovExceptionHandler.handlerResponse만 수정했습니다.application/json;charset=UTF-8로 명시(new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8)).getBytes(StandardCharsets.UTF_8)로 변경.기존 로직과 메서드 시그니처는 그대로 두었습니다.
테스트 방법
EgovExceptionHandlerTest에 회귀 테스트를 추가했습니다.application/json;charset=UTF-8인지 단정을 추가. 이 단정은 수정 전(charset 미명시)에는 실패하고 수정 후 통과하므로, 플랫폼 기본 charset과 무관하게 결정적으로 검증됩니다.EgovServiceException경로를 추가해 응답 본문을 UTF-8로 디코딩했을 때 한글이 보존되는지 단정.테스트 2건 통과(실패 0).
영향 범위