1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00
Commit Graph

1622 Commits

Author SHA1 Message Date
Emanuele Torre
4ebd21e1eb Allow passing the inline jq script before --
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-10-04 00:00:46 -05:00
Thomas Bozeman th026106
7f547827e4 Simplify pick example
Old pick example included input array in command line, making `input` confusing
and redundant.
2023-10-03 22:48:12 +02:00
Emanuele Torre
6b5a18f036 Actually use number correctly casted from double to int as index
The code was using (int)jv_number_value(k) instead of (int)didx.

follow-up from 0e067ef936

Useless assignments to didx detected by clang-tidy.
2023-09-27 22:54:23 -05:00
Emanuele Torre
8206bc8fd2 main.c: Remove unused EXIT_STATUS_EXACT option
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-27 21:52:23 -05:00
Emanuele Torre
623ace27e8 Remove a bunch of unused variables, and useless assignments
Detected by clang-tidy.
2023-09-27 21:50:44 -05:00
Emanuele Torre
2b709727a9 Remove unused nref accumulator in block_bind_library
detected as a warning compiling jq with clang.
2023-09-27 21:50:44 -05:00
itchyny
07149397d1 Reject U+001F in string literals (fix #2909) 2023-09-26 12:53:44 -05:00
itchyny
e526df15fe Correct typo in README.md: compilation (#2912) 2023-09-26 19:49:07 +02:00
taoky
8f81668014 Fix the default colors to use 39, the default foreground color (#2904) 2023-09-22 09:18:41 +09:00
dependabot[bot]
de1c10ca8a Bump docker/setup-qemu-action from 2 to 3 (#2900)
Bumps [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) from 2 to 3.
- [Release notes](https://github.com/docker/setup-qemu-action/releases)
- [Commits](https://github.com/docker/setup-qemu-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: docker/setup-qemu-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 18:20:43 +09:00
dependabot[bot]
a5afeea0a6 Bump docker/setup-buildx-action from 2 to 3 (#2901)
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2 to 3.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](https://github.com/docker/setup-buildx-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 18:20:20 +09:00
dependabot[bot]
b0b7614daf Bump actions/checkout from 1 to 4 (#2902)
Bumps [actions/checkout](https://github.com/actions/checkout) from 1 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v1...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 18:19:51 +09:00
Kamontat Chantrachirathumrong
d3a356fa1c Fix checksum file spacing for shasum command (#2899) 2023-09-17 20:55:56 +09:00
dependabot[bot]
24e6e6ea39 Bump actions/upload-artifact from 2 to 3
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-15 13:44:46 +02:00
dependabot[bot]
fb493df018 Bump crazy-max/ghaction-import-gpg from 5 to 6
Bumps [crazy-max/ghaction-import-gpg](https://github.com/crazy-max/ghaction-import-gpg) from 5 to 6.
- [Release notes](https://github.com/crazy-max/ghaction-import-gpg/releases)
- [Commits](https://github.com/crazy-max/ghaction-import-gpg/compare/v5...v6)

---
updated-dependencies:
- dependency-name: crazy-max/ghaction-import-gpg
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-15 13:43:44 +02:00
dependabot[bot]
f3a46a62de Bump docker/metadata-action from 4 to 5
Bumps [docker/metadata-action](https://github.com/docker/metadata-action) from 4 to 5.
- [Release notes](https://github.com/docker/metadata-action/releases)
- [Upgrade guide](https://github.com/docker/metadata-action/blob/master/UPGRADE.md)
- [Commits](https://github.com/docker/metadata-action/compare/v4...v5)

---
updated-dependencies:
- dependency-name: docker/metadata-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-15 13:42:32 +02:00
dependabot[bot]
e69398ea0f Bump docker/build-push-action from 4 to 5
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 4 to 5.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v4...v5)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-15 13:41:27 +02:00
dependabot[bot]
dfd930f81a Bump docker/login-action from 2 to 3
Bumps [docker/login-action](https://github.com/docker/login-action) from 2 to 3.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-15 13:40:33 +02:00
Yeikel
4c6f6dc231 Add dependabot (#2889) 2023-09-15 20:09:07 +09:00
itchyny
5ea1a4ab3b Disable core.autocrlf on Windows to prevent submodule diffs (fix #2886) (#2888) 2023-09-15 20:08:20 +09:00
Owen Ou
7a72f58d2e Standarize arch types to AMD64 & ARM64 from index page download dropdown (#2884)
Standarize arch types to AMD64 & ARM64 from index page download
dropdown. These are missed from https://github.com/jqlang/jq/pull/2879.
2023-09-07 11:55:14 -07:00
Owen Ou
806475da29 Update webpage with 1.7 release (#2879)
* Update webpage with 1.7 release

Update webpage with 1.7 release

* Update docs/content/download/default.yml

Co-authored-by: itchyny <itchyny@cybozu.co.jp>

* Update docs/templates/index.html.j2

Co-authored-by: itchyny <itchyny@cybozu.co.jp>

* Update docs/content/download/default.yml

Co-authored-by: itchyny <itchyny@cybozu.co.jp>

* Don't mention 1.7rc signatures

* Add link to 1.7 manual

* binaries -> binary

* AMD 32-bit to i386

* Standarize arch types to AMD64, ARM64 & i386 in download page

---------

Co-authored-by: itchyny <itchyny@cybozu.co.jp>
2023-09-07 10:54:10 -07:00
github-actions[bot]
4b579ca31f Update signatures of 1.7 2023-09-06 17:53:36 -05:00
Nicolas Williams
11c528d04d Add setlocale() call (fix #1740) jq-1.7 2023-09-06 14:05:10 -05:00
Nicolas Williams
ac3b70d3a1 Add a thank you note to the new owners, admins, and maintainers, and to @stedolan 2023-09-06 13:01:44 -05:00
Nico Williams
df95871dd7 Fix leak on too-large programs, OSS Fuzz issue 61349
A very large program can cause these leaks:

  ==758838== 7,820 (16 direct, 7,804 indirect) bytes in 2 blocks are definitely lost in loss record 17 of 28
  ==758838==    at 0x4848A23: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==758838==    by 0x125D30: jv_mem_calloc (jv_alloc.c:153)
  ==758838==    by 0x162ADE: compile (compile.c:1286)
  ==758838==    by 0x162D4B: compile (compile.c:1304)
  ==758838==    by 0x163697: block_compile (compile.c:1381)
  ==758838==    by 0x11B5CA: jq_compile_args (execute.c:1245)
  ==758838==    by 0x115E20: main (main.c:691)
  ==758838==
  ==758838== 1,674,694 (103,576 direct, 1,571,118 indirect) bytes in 1,177 blocks are definitely lost in loss record 28 of 28
  ==758838==    at 0x4843839: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==758838==    by 0x125CD0: jv_mem_alloc (jv_alloc.c:141)
  ==758838==    by 0x162B19: compile (compile.c:1289)
  ==758838==    by 0x163697: block_compile (compile.c:1381)
  ==758838==    by 0x11B5CA: jq_compile_args (execute.c:1245)
  ==758838==    by 0x115E20: main (main.c:691)

This commit fixes that.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61349
2023-08-29 10:27:41 +02:00
github-actions[bot]
91d72575e4 Update signatures of 1.7rc2 2023-08-27 12:53:29 -05:00
Nicolas Williams
0e067ef936 Improve handling of non-integer numeric indices (fix #2815) jq-1.7rc2 2023-08-27 12:32:12 +02:00
Emanuele Torre
ab47880b4c Make jq_get_lib_dirs return an empty array if JQ_LIBRARY_PATH is not set
For the jq_state used by the jq utility, the JQ_LIBRARY_PATH attribute
will always be set, but, in general, it is possible that it might not
be.

If it is not set, jq_get_lib_dirs() will return jv_invalid().

That is not good, because some code in linker.c expects it to always
returns an array.

This patch makes jq_get_lib_dirs() return an empty array if
JQ_LIBRARY_PATH is not set to prevent problems.

This issue made OSS fuzz trigger failed assertions every time it tried
to compile a script that uses "include".

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61796
2023-08-27 00:37:54 -05:00
Emanuele Torre
6436f1e0f8 Fix memory leak in find_lib for some invalid inputs 2023-08-26 17:17:29 -05:00
Nicolas Williams
2c3561810d Check nomem_handler->handler before calling it 2023-08-25 10:13:46 -05:00
itchyny
70807e2b1b Include more updates to NEWS.md and AUTHORS for 1.7 2023-08-23 15:59:19 -05:00
itchyny
080471b2a0 Add src/config_opts.inc to .gitignore 2023-08-21 16:06:58 +02:00
Nicolas Williams
583e4a2718 Add --config option printing ./configure options used 2023-08-19 17:40:08 -05:00
itchyny
7d64381016 Fix overflow on numeric comparison (#2849)
Although #2839 fixed the overflow of exponent subtraction,
there still is possibility of overflow in the `D2U` macro.
This patch fixes the overflow in the `D2U` macro, and also
truncates the maximum digits to `DEC_MAX_DIGITS`.
2023-08-17 15:56:57 +09:00
itchyny
0733fd3d58 Add a regression test for negative indices and fix a pick/1 test 2023-08-16 17:49:44 -05:00
itchyny
f85c9fcb78 Revert "Allow .[-1] in path expressions"
This reverts commit 086a156ec3.

This commit leads to negative indexing wraps twice.
2023-08-16 17:49:44 -05:00
Emanuele Torre
4cf1408e0b Cast function pointers without prototype before calling them (#2842)
clang complained that this is deprecated in all versions of standard C,
and unsupported in C2x.
2023-08-13 22:39:54 +09:00
itchyny
3fa10e8cc1 Fix crash on numeric comparison again (ref #2825)
The decNumber library subtracts the exponents of two numbers,
we make sure to limit the number of digits not to make it overflows.
Since the maximum adjusted exponent is `emax` and the minimum is
`emin - digits + 1`, we follow `emax - (emin - digits + 1) <= INT32_MAX`.
2023-08-13 14:17:25 +02:00
itchyny
f86566b263 Rename jv_type_private.h to jv_private.h, move jvp_number_is_nan there 2023-08-13 14:16:02 +02:00
Alex Wilson
f31c180e8f Update documentation to reflect new defs field on modulemeta 2023-08-12 20:46:36 -05:00
Alex Wilson
65ed95c93a Expose the names of a module's defined function via modulemeta
This reuses the existing `block_list_funcs` capability and adds an extra field on the `modulemeta` output, called `defs`, containing that list of functions.
2023-08-12 20:46:36 -05:00
Mattias Wadman
fdab39bc7b Build windows 64bit binary using UCRT64 (#2832)
* Build windows 64bit binary using UCRT64

Is the default and recommended msystem setting. Will produce
binaries that are compatible with windows 10 and later.

Also run tests for 32bit build.

Related to #2831

* Use jq -b in tests/shtest

* Add Windows strptime

* Make Windows-optional tests not run on Windows again

---------

Co-authored-by: Nicolas Williams <nico@cryptonector.com>
2023-08-12 20:18:45 +02:00
Mattias Wadman
5a52553a3b Make sure to init key and dbl_key also on win32
Hopefully fixes page fault for mingw build

Related to #2831
2023-08-10 13:06:03 -05:00
Mattias Wadman
765a5c77eb Make sure to init dtoa_ctx_key also on win32 (#2834)
Fixes page fault for mingw build

Related to #2831
2023-08-10 18:53:50 +02:00
Naïm Favier
d1a6da2205 docs: fix delpaths description 2023-08-09 18:20:04 +02:00
itchyny
a692060129 Change the default color of null to Bright Black 2023-08-05 23:21:12 -05:00
Emanuele Torre
f94a9d463f Let error(null) throw null
This patch removes the weird behaviour of jv_invalid_with_msg(jv_null())
that returns jv_invalid() (i.e. empty), instead of a boxed jv_null().

The previous behaviour of  null|error  was obviously unintentional, and
allowing is jv_invalid_with_msg() to return values on which you can't
call jv_invalid_get_msg() is only error prone.
2023-08-04 17:38:52 -05:00
Emanuele Torre
3b6e7ddd72 Constant fold all kinds of constants
This patch exports all the binary operator builtins functions from
builtin.c and uses them for constant folding in the parser, allowing
constant folding to work will all kinds and combinations of constants.

Now string*number,  $ARGS+$ARGS,  string/string,  etc will also be
constant folded and the implementation of constant folded operators and
runtime operators will be the same.

And thanks to the new ERRORK bytecode operation, errors are constant
folded too! (e.g. 1 / 0   [] * {}   etc)
2023-08-04 11:47:34 -05:00
Emanuele Torre
5fc5453409 Add ERRORK opcode to trigger constant errors 2023-08-04 11:47:34 -05:00