Skip to content

Fix decimal alias negative values with prefix/groupSeparator collision (#2262)#2882

Open
thorn0 wants to merge 1 commit into
RobinHerbots:5.xfrom
thorn0:fix/decimal-negative-prefix-2262
Open

Fix decimal alias negative values with prefix/groupSeparator collision (#2262)#2882
thorn0 wants to merge 1 commit into
RobinHerbots:5.xfrom
thorn0:fix/decimal-negative-prefix-2262

Conversation

@thorn0
Copy link
Copy Markdown
Contributor

@thorn0 thorn0 commented Apr 10, 2026

Closes #2262, closes #2678, closes #2771

Summary

Three root causes fixed in the numeric extensions:

  1. groupSeparator definition ordering — Register the groupSeparator definition before autoEscape(prefix) so that a shared character (e.g. space in prefix "€ " with groupSeparator: " ") is escaped as a literal in the mask instead of being treated as a dynamic placeholder by the lexer.

  2. strip-negation-on-zero matching — In onBeforeWrite's strip-negation-on-zero path, match against the raw buffer instead of the stripped buffer so that prefix/suffix characters coinciding with the groupSeparator are not accidentally removed. Extracted the shared regex into a reusable matchNumberInWrapper() helper.

  3. empty radixPoint guard — Guard the radixPoint replacement with a truthiness check to prevent "".replace("", ".") from injecting a stray "." when radixPoint is empty (radix-less masks with empty placeholder).

Test plan

  • Added 18 QUnit tests in tests_formatvalidate.js covering:
    • isValid / format with negative values + prefix + groupSeparator
    • Space groupSeparator colliding with space in prefix ("€ ")
    • Suffix collision symmetry (" €")
    • Large numbers with grouping (-1 234 567.89)
    • Strip-negation-when-zero with colliding prefix/suffix
    • Radix-less masks (radixPoint: "") with integer/decimal/numeric aliases
    • Parenthetical negation (negationSymbol: { front: "(", back: ")" })
    • Round-trip: formatted output accepted as valid input

AI disclosure

This PR was written primarily by Claude Code. Follow-up fixes were reviewed and amended by Codex.

…RobinHerbots#2262

Three root causes fixed in the numeric extensions:

1. Register the groupSeparator definition before autoEscape(prefix) so that
   a shared character (e.g. space in prefix "€ " with groupSeparator " ")
   is escaped as a literal in the mask instead of being treated as a dynamic
   placeholder by the lexer.

2. In onBeforeWrite's strip-negation-on-zero path, match against the raw
   buffer instead of the stripped buffer so that prefix/suffix characters
   coinciding with the groupSeparator are not accidentally removed. Extract
   the shared regex into a reusable matchNumberInWrapper() helper.

3. Guard the radixPoint replacement with a truthiness check to prevent
   "".replace("", ".") from injecting a stray "." when radixPoint is empty
   (radix-less masks with empty placeholder).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@thorn0 thorn0 force-pushed the fix/decimal-negative-prefix-2262 branch from c472d47 to a0df91f Compare April 10, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant