fengari-lua / fengari

🌙 φεγγάρι - The Lua VM written in JS ES6 for Node and the browser
MIT License
1.8k stars 64 forks source link

Wrong behavior of string.format #147

Open Egor-Skriptunoff opened 5 years ago

Egor-Skriptunoff commented 5 years ago

C language docs says the following about .precision field in sprintf() format:

If the period is specified without an explicit value for precision, 0 is assumed.

But Fengari raises error instead of assuming zero:

   > print(("%.0f"):format(42.5))
   43
   > print(("%.f"):format(42.5))
   SyntaxError: [sprintf] unexpected placeholder
daurnimator commented 5 years ago

fengari uses the sprintf-js npm package for string formatting. Can you replicate the issue with that?

daurnimator commented 5 years ago

Can you replicate the issue with that?

Yep:

$ node
> require("sprintf-js").sprintf("%.f", 2)
Thrown:
SyntaxError: [sprintf] unexpected placeholder
> require("sprintf-js").sprintf("%.0f", 2)
'2'

Filed https://github.com/alexei/sprintf.js/issues/181