toss / es-hangul

A modern JavaScript library for handling Hangul characters.
https://es-hangul.slash.page/
MIT License
1.24k stars 83 forks source link

fix: amountToHangul이 선행 0이 있는 문자열을 잘못 변환하는 오류를 수정합니다. #168

Closed jungwoo3490 closed 1 month ago

jungwoo3490 commented 2 months ago

Overview

resolve #167

Issue에도 설명되었듯이, amountToHangul이 선행 0이 있는 문자열을 처리할 경우 의도치 않은 동작을 하는 것을 확인했어요.

image

이를 해결하기 위해 다음과 같이 integerPart의 선행 0을 모두 제거하는 로직을 추가했어요.

const integerPart = tempIntegerPart !== '0' ? tempIntegerPart.replace(/^0+/, '') : tempIntegerPart;

여기서 '0'인지 검사하는 이유는, tempDecimalPart가 존재하지 않는 상황에서 integerPart가 위 정규표현식에 의해 제거되어 빈 문자열이 되게 되면

if (integerPart === '0' || (integerPart === '' && tempDecimalPart))

이 조건식이 false가 되어 결국 '0'일 경우 "영"이 아닌 빈 문자열로 변환을 하게 되는 문제가 발생하는 것을 확인했어요.

그래서 '0'이 입력으로 들어왔을 경우만 선행 0을 제거하는 정규표현식이 동작하지 않도록 해주었습니다.

PR Checklist

  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.
changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: 4a615ae137b1450d6151935d42db5f9bd05ef90a

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-hangul ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 3:06pm
codecov-commenter commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (8f7cc9a) to head (d5da627). Report is 1 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/toss/es-hangul/pull/168/graphs/tree.svg?width=650&height=150&src=pr&token=My9jTW6bSr&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toss)](https://app.codecov.io/gh/toss/es-hangul/pull/168?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toss) ```diff @@ Coverage Diff @@ ## main #168 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 16 16 Lines 260 261 +1 Branches 58 59 +1 ========================================= + Hits 260 261 +1 ```
jungwoo3490 commented 2 months ago

@okinawaa 리뷰 반영 완료했습니다!! 확인 부탁드려요 :)