fix: read parenthesised accounting negatives on paste - #13
Merged
Conversation
(1,234) — what Excel's accounting format and most ERP exports produce — parsed to 1234, silently flipping the sign on pasted money. For a library whose whole pitch is money-safe values in legacy Korean business forms, that is a correctness bug, not a formatting nicety. parse now normalizes the input once (full-width parens included) and reads the parenthesised form as negative when the negative option is on. The parens must actually enclose digits, so '(주)한국 1234' is untouched; currency signs may sit outside them; a minus inside does not negate twice; positive-only fields ignore the form entirely. Parens stay insignificant for caret math, so cursor behaviour is unchanged. Verified in a real browser as well as jsdom (this repo has a history of DOM bugs that whole-value unit tests missed): pasting (1,234) into a bound negative field displays -1,234 and getValue returns -1234.
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.
The bug
(1,234)— the parenthesised negative that Excel's accounting format and most ERP exports produce — parsed to1234, silently flipping the sign on pasted money. For a library whose pitch is money-safe canonical values in legacy Korean business forms (JSP/eGovFrame, ERP exports), that's a correctness bug rather than a formatting nicety.The fix
parsenormalizes the input once (full-width parens()included) and reads the parenthesised form as negative whennegativeis on. Deliberately conservative:(주)한국 1234is untouched₩(1,234),(1,234)원(-1,234)→-1234(1,234)→1234Trailing-sign notation (
1234-, mainframe exports) is deliberately not included — it's ambiguous against live typing, unlike the paren form.Verification
(1,234)into a boundnegativefield displays-1,234andgetValue()returns-1234;₩(1,234.56)→-1,234.56; a positive-only field still shows1,234.Docs: Notes bullet in both READMEs, CHANGELOG 0.4.2, version bumped.