Proof that it's invalid:
------------------------------- foo.js -------------------------------
const Format = imports.format;
String.prototype.format = Format.format;
print("%.f".format(3.
1415916535));
----------------------------------------------------------------------
$ gjs foo.js
* gettext-tools/src/format-invalid.h (INVALID_PRECISION_MISSING): New macro.
* gettext-tools/src/format-java-printf.c (INVALID_PRECISION_MISSING): Remove
macro.
* gettext-tools/src/format-javascript.c: Fix comment regarding the precision.
(format_parse): Report an error if the precision is null (empty).
* gettext-tools/tests/format-javascript-1: Add a test case with null precision.
/* Common reasons that make a format string invalid.
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003-2025 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software: you can redistribute it and/or modify
#define INVALID_MIXES_NUMBERED_UNNUMBERED() \
xstrdup (_("The string refers to arguments both through absolute argument numbers and through unnumbered argument specifications."))
+#define INVALID_PRECISION_MISSING(directive_number) \
+ xasprintf (_("In the directive number %u, the precision is missing."), directive_number)
+
#define INVALID_ARGNO_0(directive_number) \
xasprintf (_("In the directive number %u, the argument number 0 is not a positive integer."), directive_number)
#define INVALID_WIDTH_ARGNO_0(directive_number) \
#define INVALID_LAST_ARG(directive_number) \
xasprintf (_("In the directive number %u, the reference to the argument of the previous directive is invalid."), directive_number)
-#define INVALID_PRECISION_MISSING(directive_number) \
- xasprintf (_("In the directive number %u, the precision is missing."), directive_number)
-
#define INVALID_FLAG_FOR(directive_number,flag_char,conv_char) \
xasprintf (_("In the directive number %u, the flag '%c' is invalid for the conversion '%c'."), directive_number, flag_char, conv_char)
while (c_isdigit (*format))
format++;
+ /* Parse precision. */
if (*format == '.')
{
format++;
- while (c_isdigit (*format))
- format++;
+ if (!c_isdigit (*format))
+ {
+ if (*format == '\0')
+ {
+ *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE ();
+ FDI_SET (format - 1, FMTDIR_ERROR);
+ }
+ else
+ {
+ *invalid_reason = INVALID_PRECISION_MISSING (spec.directives);
+ FDI_SET (format, FMTDIR_ERROR);
+ }
+ goto bad_format;
+ }
+
+ do format++; while (c_isdigit (*format));
}
switch (*format)
"abc%y"
# Invalid: flags after width
"abc%1Ig"
+# Invalid: null precision
+"abc%.f"
# Invalid: twice precision
"abc%.4.2f"
# Valid: three arguments