fix: EgovStringUtil.alignLeft 생략 표기 시 원본 전체가 앞에 붙는 문제 수정 - #302
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.
변경 이유
EgovStringUtil.alignLeft(str, length, true)는 원본이 지정 길이보다 길 때 결과 길이가 지정 길이를 넘습니다. 결과 버퍼를new StringBuilder(str)로 만들어 원본 전체를 이미 담은 상태에서, 잘라낸 앞부분과"..."를 뒤에 다시 붙이기 때문입니다.같은 클래스의
alignRight,alignCenter는 버퍼를new StringBuilder(length)로 시작해 생략 표기가 지정 길이 안에 들어갑니다. 위와 같은 입력에"ab..."를 반환합니다. 세 메서드는 정렬 방향만 다를 뿐 생략 표기 규칙은 같아야 하므로, 형제 메서드의 동작을 기준으로alignLeft를 맞췄습니다.str = "abcdefghij"기준 실측 대조입니다.abcdefghij.........abcdefghijab...ab...ab...abcdefghijabcdefghijabcdefghij수정 후에는
alignLeft의 출력이 전 구간에서alignRight,alignCenter와 일치합니다.변경 내용
alignLeft(String, int, boolean)의 버퍼 초기화를new StringBuilder(str)에서new StringBuilder(length)로 바꾸고 패딩 경로에서 원본을append(str)로 붙입니다.alignRight와 같은 형태입니다.EgovStringUtilTest에testAlignStringWithEllipsis를 추가했습니다. 세 메서드의 생략 표기, 자르기, 패딩, 빈 문자열,null입력을 한자리에서 검증합니다.테스트 방법
mvn -pl Foundation/org.egovframe.rte.fdl.string testTests run: 55, Failures: 0, Errors: 0으로 통과했습니다. 수정 전 코드로 되돌리면 새 테스트가 아래와 같이 실패해, 결함을 그대로 잡아냅니다.영향 범위
isEllipsis가true이면서 원본이 지정 길이보다 긴 경로뿐입니다.isEllipsis가false인 경로는length가 0 이상인 전 구간에서 출력이 같습니다. 패딩 경로와 빈 문자열, 길이가 정확히 같거나 미달인 경우도 그대로입니다.alignLeft,alignRight,alignCenter를 호출하는 곳이 유틸 자신 외에는 없습니다. 기존 출력에 기대어 동작하는 코드는 발견되지 않았습니다.length에 음수를 넘기면 예외 타입이StringIndexOutOfBoundsException에서NegativeArraySizeException으로 바뀝니다.alignRight,alignCenter가 이미 같은 예외를 내던 자리라 세 메서드의 동작이 맞춰지는 방향입니다.