Fix whitespace in number parsing (#3195)
* Handle input errors for --indent
Handle malformed and overflowing arguments. Also, forbid leading and
trailing spaces to match the behavior of tonumber from commit ce0e788
(improve tonumber/0 performance by parsing input as number literal,
2024-03-02).
* Do not skip leading whitespace in jvp_strtod
`jvp_strtod` skips leading whitespace, but its decnum counterpart
`decNumberFromString` (called within `jv_number_with_literal`) does not.
Those two are called interchangeably, so it leads to inconsistent
behavior depending on whether the decnum feature is enabled.
Additionally, `classify`, used in the token scanner, only considers
[ \t\n\r] to be whitespace, but `jvp_strtod` consumes the larger set
[ \t\n\v\f\r], so those extra characters are considered literals.
Changing this deviates from the behavior of `strdod` from <stdlib.h> and
is technically a breaking API change, since it is a public symbol.
This commit is contained in:
1 parent
aaace5432a
commit
9ac6ddae22
3 files changed
+11
-16
No files matched your search
+6
-3
@@ -422,12 +422,15 @@ int main(int argc, char* argv[]) {
|
||||
fprintf(stderr, "jq: --indent takes one parameter\n");
|
||||
die();
|
||||
}
|
||||
dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7));
|
||||
int indent = atoi(argv[i+1]);
|
||||
if (indent < -1 || indent > 7) {
|
||||
char* end = NULL;
|
||||
errno = 0;
|
||||
long indent = strtol(argv[i+1], &end, 10);
|
||||
if (errno || indent < -1 || indent > 7 ||
|
||||
isspace(*argv[i+1]) || end == argv[i+1] || *end) {
|
||||
fprintf(stderr, "jq: --indent takes a number between -1 and 7\n");
|
||||
die();
|
||||
}
|
||||
dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7));
|
||||
dumpopts |= JV_PRINT_INDENT_FLAGS(indent);
|
||||
i++;
|
||||
} else if (isoption(&text, 0, "seq", is_short)) {
|
||||
|
||||
Reference in new issue
Block a user