11 Commits
Author SHA1 Message Date
Thalia Archibald 9ac6ddae22 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.
2025-05-29 04:11:00 +09:00
Thalia Archibald 32a304b912 Clarify -f argument parsing (#3199) 2024-11-09 15:48:24 +01:00
Thalia Archibald eb9bdca296 Remove outdated FIXME
This comment predates the addition of $ARGS in jq 1.6, so there was no
way to access named arguments with an invalid identifier. Rather than
forbid such names, update the manual to clarify.
2024-11-08 19:07:55 +01:00
Thalia Archibald 7cac5e80ec Remove dead flag 2024-11-08 19:07:55 +01:00
Thalia Archibald 7a1fd72d2d Fix missing program from file
When jq is not supplied with a program, it usually exits with an error
and usage text, except for when jq is not connected to a TTY (i.e., not
interactive), in which case a default program of `.` is used. Combined
with `-f`, it then tries to read `.` as the filename.

    $ jq
    jq - commandline JSON processor [version 1.7.1]
    …
    $ jq -f
    jq - commandline JSON processor [version 1.7.1]
    …
    $ jq | cat
    ^C
    $ jq -f | cat
    jq: Could not open .: It's a directory
2024-11-08 19:07:55 +01:00
Thalia Archibald 0558e77e8c Add --library-path long option for -L
-L is the only option without a long form.
2024-11-08 19:07:55 +01:00
Thalia Archibald ff4acba769 Parse short options in order given
Fixes:
* Short options cannot be repeated in the same group:
  e.g., `-nn` fails, but `--null-input --null-input` works
* Short options are processed in an arbitrary fixed order, not the order
  given by the user: e.g., `-hV`, `-Vh`, `-h -V`, and `--help --version`
  are processed as `-h`, but `-V -h` and `--version --help` are
  processed as `-V`
* `-L` cannot be a part of a short option group (as the last one):
  e.g., `-nLlib` and `-nL lib` fail
2024-11-08 19:07:55 +01:00
Thalia Archibald 54cc15c127 Add missing string color case
Colors have a color separate from object keys, so were not tested.
2024-02-08 00:11:54 -06:00
Thalia Archibald 48df9bce0c Clear formatting immediately after colon 2024-02-08 00:11:54 -06:00
Thalia Archibald 76853f6046 Fix tests and test indented printing 2024-02-08 00:11:54 -06:00
Thalia Archibald 3c37522aaa Consistently reset color formatting in jv_dump_term
Before, arrays would not reset colors after `[` and `,`, but objects
would; it would reset colors twice before `]` and `}`; and some cases of
indentation would have colors applied. Now, colors are reset immediately
after any token that is colored, before any indentation. This makes the
formatting consistent, for the benefit of custom `JQ_COLORS`.
2024-02-08 00:11:54 -06:00