luckyframework / lucky

A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts.
https://luckyframework.org
MIT License
2.57k stars 156 forks source link

Malformed format string with 0 precision #1731

Closed jwoertink closed 1 year ago

jwoertink commented 1 year ago

https://github.com/luckyframework/lucky/blob/dd61285fd250f6b18a8b9ceb80e2484e50773e84/src/lucky/page_helpers/number_to_currency.cr#L24

Passing a precision of 0 will those that error "%.0f" % 100.0

stephendolan commented 1 year ago

Here's a play link with the error: https://play.crystal-lang.org/#/r/dqf8

jwoertink commented 1 year ago

Turns out this is a Crystal bug... maybe fixed by https://github.com/crystal-lang/crystal/pull/12448 ?

I tried against 1.6.0-dev and it works, but 1.5.1 it's broken.

❯ ./bin/crystal eval 'pp "%.0f" % 100.0'
Using compiled compiler at .build/crystal
"100"

❯ crystal eval 'pp "%.0f" % 100.0'
Unhandled exception: Malformed format string - %'0' (ArgumentError)
jwoertink commented 1 year ago

Closing this since it'll be fixed by Crystal 1.6 being released next week.