summaryrefslogtreecommitdiffstats
path: root/src/main.c
AgeCommit message (Collapse)Author
2024-01-16Revert "lexer: temporarily revert #\ patch; keep CR in comment bug fix"Emanuele Torre
This reverts commit 5d95791a6795bfc44380c2e6e343ee66dd891e8b.
2023-12-13lexer: temporarily revert #\ patch; keep CR in comment bug fixEmanuele Torre
This commit temporarily reverts the commit that allows #\ "tcl-style" comments everywhere and documents them, for the 1.7.1 patch release cca1f7d18f2fa6721952645821ae429a0166d7e4. \r is removed from the list of characters not allowed in a comment to preserve that bugfix.
2023-11-03Comment bug fixes, and fully support Tcl-style multiline commentsEmanuele Torre
* bugfix: comments were incorrectly being terminated by CR; for example jq -n $'1 #foo\r' fails to compile because the CR character terminates the comment, and CR is not a valid character in jq syntax. * improvement: comments fully support Tcl-style line continuation. Previously this was only "supported" in `-f' scripts, whose first line starts with "#!", and second line starts with # and ends with \, only for the comment on the second line, only for one extra line. * man: document comment syntax, which was previously undocumented. * tests: add regression tests for the bugfix, and some tests for line continuation in comments.
2023-10-22Fix possible uninitialised value dereference if jq_init() failsEmanuele Torre
If jq_init() fails, goto out would try to free input_state which is uninitialised. I initialised input_state to NULL to fix the problem. Ref: https://github.com/jqlang/jq/pull/2934#discussion_r1367795641 Reported-By: Klemens Nanni <kn@openbsd.org>
2023-10-21Defer heap variable initialisation after pledgeKlemens Nanni
Otherwise `AGRS` and `program_arguments` remain allocated/unfreed in the early (extremely unlikely) pledge(2) failure case. Move their allocation before jq_init(), the first case of jumping to `out` where they are cleaned up, where it also seems to logically fit better than above between function entry, locale setup and OpenBSD specific pledge.
2023-10-21Restrict systems operations on OpenBSDKlemens Nanni
Use pledge(2)[0] to limit jq(1) to reading files. It does not change files and only writes to standard output/error. It never deals with TTY, network, process management or other subsystems. This is to reduce jq's attack surface and potential damage. OpenBSD is carrying a local patch[1] in its official jq port/package since 2016. An improved version: - drop no longer needed "getpw" promise f1c4947 "Avoid getpwuid for static linking" removed getpwuid(3) usage - pledge before jq_init() to simplify the error path - use perror(3) to print errno(2) No behaviour change in tests or real world usage observed on OpenBSD/amd64 7.4. 0: https://man.openbsd.org/pledge.2 1: https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/textproc/jq/patches/patch-main_c
2023-10-04Allow passing the inline jq script before --Emanuele Torre
jq previously only allowed passing the inline script before -- (as if they were options) even though one would expect the inline script to be a positional argument. Since jq previously also refused to run with a usage error if the script was passed after -- (It was not assuming . as script as it does when no arguments are passed), and positional arguments are allowed before -- and even before other options, it should not be a breaking change to change that weird behaviour, and allow the script to appear after --. It also simplifies the option parsing code a bunch. Fixes #2918
2023-09-27main.c: Remove unused EXIT_STATUS_EXACT optionEmanuele Torre
In process there is a suspicious options |= EXIT_STATUS_EXACT that is run when the jq script is terminated by halt, or halt_error. That line of code acutally does nothing because options is a local argument variable, and is not passed as a pointer. It was probably meant to be a *options |= EXIT_STATUS_EXACT with the options argument passed as a int*. In any case, we do not want to run the code in main() that was supposed to run if EXIT_STATUS_EXACT is set (but didn't since it is never added to options); as far as I can tell, we only want to run that code when the --exit-status/-e option is passed. So I removed EXIT_STATUS_EXACT completely, and the useless assignment, instead of fixing it since it was not used for anything else. Useless assignment detected by clang-tidy.
2023-09-06Add setlocale() call (fix #1740)jq-1.7Nicolas Williams
2023-08-19Add --config option printing ./configure options usedNicolas Williams
2023-07-31Massage --help text to use max 72 characters widthMattias Wadman
2023-07-26Rename --nul-output to --raw-output0, abort on string containing NULitchyny
The option naming --nul-output was confusing, especially when we have a similar option for input stream in the future (--nul-input vs --null-input). Based on the observation of other command line tools, we rename the option to --raw-output0. We also drop the short option -0 to avoid confusion on introducing the NUL-delimited input option. Unlike the other command line tools outputting file names with NUL delimiter, jq deals with JSON, and its strings may contain NUL character. To protect users from the risk of injection attacks, we abort the program and print an error message before outputting strings including NUL character. Closes #2683.
2023-07-25Remove deprecated --argfile optionitchyny
2023-07-25Align prompt in help exampleMattias Wadman
Was accidentally unaligned in #2747 Now looks like this: Example: $ echo '{"foo": 0}' | jq . { "foo": 0 } Before looks like this: Example: $ echo '{"foo": 0}' | jq . { "foo": 0 }
2023-07-25Reorder the command line options in the manual (#2766)itchyny
2023-07-23Fix stderr to output string with no decoration (fix #2063)itchyny
2023-07-23Fix --stream-errors w/o --stream, and doc+test (close #2748)Nicolas Williams
2023-07-23Improve --help to mention all the command optionsitchyny
2023-07-19Move options to main and pass it to processRobert Aboukhalil
2023-07-19Reset options to 0 so can call main() multiple times in a rowRobert Aboukhalil
2023-07-19Respect NO_COLOR environment variable to disable color outputitchyny
2023-07-14Fix memory leak on halt_error/1itchyny
2023-07-07exit immediately after halt or halt_error is calledEmanuele Torre
Instead of continuing to the next input, and only exiting if there are no more inputs. Closes #2533
2023-07-06Fix exit code on JSON parse error (#2654)itchyny
2023-07-05Validate JSON for --jsonargMattias Wadman
Fixes #2572
2023-07-03Fix the default search paths and documentation (#2093)itchyny
2023-06-28Fix "writing output failed" error of non ASCII output on Windows (#2633)itchyny
2023-06-27Fix halt_error to print message without prefix in raw mode (fix #1902) (#2632)itchyny
2023-06-06fix handling of -0 (#2235)Anthony Sottile
2023-05-28Update URLs from stedolan to jqlangStephen Dolan
2021-09-06Fix Windows build for 1.7 release (moar)Nicolas Williams
2019-12-30Add -0 / --nul-output option for processing values containing newlinesPaul Wise
Closes: https://github.com/stedolan/jq/issues/1271
2019-03-24Identify progname in more errors (fix #1860)Nicolas Williams
However, we should really use the argv[0] progname, not just jq. Someday we may want to support aliases which automatically add certain options, etc.
2019-03-24Add -b / --binary option for WindowsNicolas Williams
2019-02-17Allow globbing on WindowsJason Hood
The mingw-w64 runtime expands wildcards, which causes a discrepancy between `main`'s `argv` (multiple file names) and Windows' `wargv` (a single wildcard). Use `wmain` to retrieve the wide character args.
2019-02-16Prevent redirecting to NUL crashJason Hood
Windows regards the `NUL` device as tty, which causes `WriteFile` to fail (the bytes written pointer cannot be `NULL` in this case). Tweak the color test to ensure tty is accurate.
2019-02-16Possibly enable color output on Windows (#1494)Jason Hood
Windows 10 supports color output, but it must be explicitly enabled; ANSICON provides support for other versions. Enable color if either of those are available. Resolves #1494.
2018-12-18fix --exit-code issues #1142 and #1139Ryoichi KATO
* Set default error code to -4 in main(), Fixes #1142 * fix --exit-code with more than one object in input, Fixes #1139 - Return code 1 or 4 based on last output, not last input.
2018-11-20Add missing jv_copy when printing with -arWilliam Langford
2018-03-01src/main.c: fix issue #1587 by using jv_dumpf in the raw-output and ↵rain1
ascii-output case. retain fwrite in the raw-output case.
2017-12-11Added rawfileDavid Fetter
In passing, clean remnants of argfile from slurpfile docs.
2017-04-29Add JQ_COLORS env var for color config (fix #1252)Nico Williams
2017-03-26Add --debug-trace=all for detailed debug outputWilliam Langford
When tracing execution, print the whole stack, not just the items used by the current opcode
2017-02-26Add `halt`, `halt_error` builtins (fix #386)Nicolas Williams
2017-02-25Add $ARGS, --args and --jsonargs (fix #1345)Nicolas Williams
2017-02-25Don't call SetConsoleOutputCPYasuhiro Matsumoto
Should use wide-string function instead of SetConsoleOutputCP. Fixes #1121
2016-01-16Fix cross-compilation buildNicolas Williams
2015-12-14Make it easier to use jq with shebangs (fix #1044)Nicolas Williams
Allow a continuation on a comment immediately after a shebang to make this traditional hack possible: #!/bin/sh # this next line is ignored by jq \ exec jq -f "$0" "$@" # jq code follows But continue only on the first line following a shebang, and only if it's a comment.
2015-12-15Add note about IEEE754 to help msgNicolas Williams
2015-12-14Change usage formattingCameron Sparr