Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix whitespace in number parsing #3195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/jv_dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2368,29 +2368,21 @@ jvp_strtod

sign = nz0 = nz1 = nz = bc.dplen = bc.uflchk = 0;
dval(&rv) = 0.;
for(s = s00;;s++) switch(*s) {
switch(*(s = s00)) {
case '-':
sign = 1;
/* no break */
JQ_FALLTHROUGH;
case '+':
if (*++s)
goto break2;
break;
/* no break */
JQ_FALLTHROUGH;
case 0:
goto ret0;
case '\t':
case '\n':
case '\v':
case '\f':
case '\r':
case ' ':
continue;
default:
goto break2;
break;
}
break2:
if (*s == '0') {
#ifndef NO_HEX_FP /*{*/
switch(s[1]) {
Expand Down
9 changes: 6 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,15 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "%s: --indent takes one parameter\n", progname);
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 == NULL || *end) {
fprintf(stderr, "%s: --indent takes a number between -1 and 7\n", progname);
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)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -2084,8 +2084,8 @@ null
2

.[] |= try tonumber
["1", "2a", "3", " 4 ", "5.67", ".89", "-876", "+5.43", 21]
[1, 3, 5.67, 0.89, -876, 5.43, 21]
["1", "2a", "3", " 4", "5 ", "6.7", ".89", "-876", "+5.43", 21]
[1, 3, 6.7, 0.89, -876, 5.43, 21]
wader marked this conversation as resolved.
Show resolved Hide resolved

# Also 1859, but from 2073
any(keys[]|tostring?;true)
Expand Down
Loading