Skip to content

parse: reject repeated declared decimal marks - #2741

Closed
ryanduguid wants to merge 1 commit into
hledgerorg:mainfrom
ryanduguid:fix/validate-declared-decimal-mark
Closed

ryanduguid wants to merge 1 commit into
hledgerorg:mainfrom
ryanduguid:fix/validate-declared-decimal-mark

Conversation

@ryanduguid

Copy link
Copy Markdown

Fixes #1985 and #1904.

With decimal-mark ., hledger currently accepts 10.999.99 AUD as 1099999 AUD. Repeated periods are classified as digit group separators before the declared format is considered. This affects journal amounts, balance assignments and CSV imports.

Pass the declared amount style to the shared number conversion. When a number has no explicit decimal part, reject grouping that uses the declared decimal mark. This applies the same validation to journal and CSV parsing, including commodity/default formats. Unambiguous formats and inference without a declaration keep their existing behaviour, so commodity display formats can still differ from the parsing format.

Add parser tests and 18 functional cases covering amounts, balance assertions and assignments, transaction prices, declaration precedence, commodity display formats, CSV fields and rule-generated amounts.

Validation on Windows with GHC 9.14.1:

  • Warning-free stack build hledger --ghc-options=-Werror --test --no-run-tests passes.
  • All 18 new functional cases pass. Against upstream f6f7661d, the same file has 11 failures and seven passes.
  • just unittest: all 252 tests pass.
  • just doctest: all 303 examples pass.
  • just embedtest: passed.
  • Full functional suite with the same Bash runner settings as the upstream baseline: 1,994 passes and 265 failures across 2,259 cases. All 265 failing cases also fail on upstream; no existing case changes from passing to failing. These include Windows executable-name, path and encoding mismatches, so this is not a full suite pass on Windows. Linux and macOS have not been tested locally.

@simonmichael simonmichael added the journal The journal file format, and its features. label Sep 22, 2026
@ryanduguid

Copy link
Copy Markdown
Author

Closing along with #2740, since both were made with AI tools and don't meet https://hledger.org/AI.html.

@ryanduguid ryanduguid closed this Sep 23, 2026
simonmichael added a commit that referenced this pull request Sep 25, 2026
…tly (#1985, #1904)

With a decimal-mark directive or decimal-mark CSV rule in effect,
a number in that file that is clearly using a different decimal mark
(like 1,000.00 when decimal-mark , is declared) is now reported as an
error rather than being accepted. So is a number using the declared
decimal mark more than once (like 1.2.34 or 10.999.99 when
decimal-mark . is declared - previously this was silently read as
1234 or 1099999). This applies to all amounts, including costs,
balance assertions, and CSV fields and rule-generated amounts.

The commodity and D directives may use a different decimal mark from the
one declared by decimal-mark, since they are only declaring display style
in that case. (And if decimal-mark is not declared, they influence
parsing as in hledger 1 - their decimal marks help interpret ambiguous
numbers like 1,000, but are not enforced otherwise. So if you want
the stricter checking, declare decimal-mark.)

It means that some existing journal files or CSV rules files with a
decimal-mark declaration, and mixed decimal marks in their data,
will now be rejected. To resolve, fix the mixed decimal marks.

Also, errors within a cost amount (after @ or @@) are now reported
specifically, instead of as a generic parse error at the @.

See also: prior work at #2741

AI usage: Claude Opus 5.5, ~83k output tokens
@simonmichael

Copy link
Copy Markdown
Member

Thank you @ryanduguid. I followed up with ac17d01 to fix the issue.

ryanduguid added a commit to ryanduguid/ryanduguid that referenced this pull request Sep 27, 2026
## Summary

The hledger fork is archived (27 September 2026) because upstream closed
hledgerorg/hledger#2740 and hledgerorg/hledger#2741 and no pull request
by me is open there. FORKS.md now says so under "Forks with no open
contribution".

## Evidence

- **Before:** `archived=false`; FORKS.md listed hledger only as due for
review.
**After:** `gh api repos/ryanduguid/hledger` reports `archived=true`;
FORKS.md records the archive.

## Merge danger

**Door:** two-way. **Blast radius:** docs

## Unverified

None.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

journal The journal file format, and its features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doubled decimal mark typo not detected, even with decimal-mark

2 participants