Commit Graph
1757 Commits
Author SHA1 Message Date
itchyny 39eea145b4 website: deploy website from GitHub Actions (#3237)
Deploying GitHub Pages from the gh-pages branch is a classic way.
We can use actions/deploy-pages action to deploy GitHub Pages.
2025-01-28 11:40:55 +09:00
Han Jiang da28628edd Fix redundant subexpression in Generators and iterators example in doc (#3239) 2025-01-27 19:45:27 +09:00
itchyny 31dac287cc tests: quote .[] in shtest which can break syntax highlight (#3235) 2025-01-26 08:08:31 +09:00
Eloy Coto 562ffec869 refactor: move bsearch function to C-code (#2945)
This commit fixes issue #527 and move the bsearch function to a native
C-code. This change improves the performance of this function.
2025-01-25 22:09:43 +09:00
Michael Färber 18bd8374c1 Escape some code parts in manual. (#3184) 2025-01-25 21:55:06 +09:00
Dag-Erling Smørgrav d8463c2549 Move closer to the standard autotools idiom. (#3187)
* Create `src/config.h` instead of passing everything on the compiler
  command line.

* To reduce the magnitude of this change, add `--include src/config.h`
  to CFLAGS instead of adding `#include "src/config.h"` at the top of
  each source file.  Not all compilers support this, but I don't think
  we care about anything other than gcc and clang at this point.

* Rather than generate `src/config_opts.inc`, emit `JQ_CONFIG` directly
  into `src/config.h`.

* Rather than generate `src/version.h`, define `JQ_VERSION` as an alias
  for the standard `PACKAGE_VERSION`.
2025-01-25 17:10:05 +09:00
itchyny 71ed7b3412 tests: refactor constant folding tests (#3233) 2025-01-25 13:58:47 +09:00
dependabot[bot] 588ff1874c build(deps): bump jinja2 from 3.1.4 to 3.1.5 in /docs (#3226)
Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.4 to 3.1.5.
- [Release notes](https://github.com/pallets/jinja/releases)
- [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst)
- [Commits](https://github.com/pallets/jinja/compare/3.1.4...3.1.5)

---
updated-dependencies:
- dependency-name: jinja2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-29 21:54:10 +09:00
lectrical bcbf2b4616 Generate provenance attestations for release artifacts and docker image (#3225)
Adding https://github.com/actions/attest-build-provenance to the ci builds so
that the release assets and docker image for the next release tag generate
signed build provenance attestations for workflow artifacts.
2024-12-29 21:53:16 +09:00
Emanuele Torre 8bcdc9304a jq_next: simplify CALL_BUILTIN implementation 2024-12-01 11:49:44 +01:00
Emanuele Torre 0b82b3841b builtin.c: typecheck builtin cfunctions in function_list
In C23 (default C standard used by GCC 15),  jv (*fptr)();  has become
equivalent to  jv (*fptr)(void);  so we can no longer assign builtin
implemenations directly to the fptr member of cfunctions without
generating a compile error.

Since there does not seem to be any straight-forward way to tell
autoconf to force the compiler to use C99 short of explicitly adding
-std=c99 to CFLAGS, it is probably a cleaner solution to just make the
code C23 compatible.

A possible solution could have been to just redeclare  cfunction.fptr
as void*, but then the functions' return type would not have been type
checked (e.g. if you tried to add a {printf, "printf", 2}, where printf
is a function that does not return jv, the compiler wouldn't have
complained.)
We were already not typechecking the arguments of the functions, so e.g.
  {binop_plus, "_plus", 3},  /* instead of {f_plus, "_plus, 3},       */
  {f_setpath, "setpath", 4}, /* instead of {f_setpath, "setpath", 3}, */
compile without errors despite not having the correct prototype.

So I thought of instead improving the situation by redefining
cfunction.fptr as a union of function pointers with the prototypes that
the jq bytecode interpreter can call, and use a macro to add the builtin
functions to function_list using to the arity argument to assign the
implementation function to the appropriate union member.

Now the code won't compile if the wrong arity, or an arity not supported
by the bytecode interpreter (>5 = 1input+4arguments), or a prototype not
jallable by the bytecode interpreter (e.g. binop_plus that doesn't
expect a  jq_state*  argument).

Also, the code now compiles with gcc -std=c23.

Fixes #3206
2024-12-01 11:49:44 +01:00
itchyny 96e8d893c1 fix: reduce/foreach state variable should not be reset each iteration (#3205)
When the UPDATE query in a reduce or foreach syntax does not emit
a value, it should simply skip updating the state variable. But
currently it resets the state variable to null.
2024-11-21 08:12:18 +09:00
Mattias Wadman 8619f8a8ac Use codepoint index for indices/1, index/ 1 and rindex/1 (#3065)
Previsouly byte index was used.

Fixes #1430 #1624 #3064
2024-11-17 10:22:05 +01:00
itchyny a7b22539a4 fix: make last(empty) yield no output values (#3179) 2024-11-13 20:35:50 +09:00
Dag-Erling Smørgrav 3c5707f7fb Improve reliability of NO_COLOR tests. (#3188)
* Improve reliability of NO_COLOR tests.

Use `env` to ensure that `NO_COLOR` is set to the desired value
regardless of any initialization that may occur when `script`
forks a shell to run jq in.

Note that `env -u` is not portable, so there is no good solution
for the first test case.

* Always use /bin/sh, not the user's login shell.
2024-11-13 20:35:22 +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
Matt Meyers 562d5c5222 Return error for string literal beginning with single quote (#2964)
In order for a string literal to be valid in JSON, the value must be
surrounded by double quotes.
2024-10-06 08:52:56 +09:00
itchyny 1bebd23aad add skip/2 as the counterpart to limit/2 (#3181)
I also changed the behavior of limit/2 with negative count to emit an error, like nth/2 does.
Also, I redefined nth/2 using skip/2 to minimize the impact of growth of builtin filters.
2024-10-06 08:25:38 +09:00
Nathan Baulch 860af44fee Fix typos (#3173) 2024-09-13 18:30:49 +09:00
Chris LaRose 37f4cd2648 Fix docs for strptime(fmt) (#3164) 2024-08-27 10:59:43 +09:00
Kirk McKelvey 6322b99252 fix: find and source ~/.jq file on windows (fixes #3104) (#3114) 2024-08-24 08:44:08 +09:00
Emanuele Torre da2a0b970c mktime/0: remove unnecessary length>=6 input requirement (#3162)
This check was redundant and useless since jv2tm() used to require 8
elements, and errored anyway if not enough elements were provided.
After commit bc96146, this check also prevents mktime/0 from accepting
now supported inputs with less than 8 elements.

Ref: https://github.com/jqlang/jq/pull/3070#issuecomment-2299902072

Reported-by: itchyny <itchyny@cybozu.co.jp>
2024-08-22 08:17:54 +09:00
fletcher gornick 0e0cdd552e feat: uri decode function (#3161) 2024-08-22 08:07:24 +09:00
myaaaaaaaaa 0b5ae30f19 Implement add/1 (#3144) 2024-08-20 21:02:24 +09:00
Emanuele Torre 137018d2ae jv.h: define empty JV_{,V}PRINTF_LIKE macros if __GNUC__ is not defined
Fixes #3159

Reported-by: Hsiang-Ying Fu
2024-08-13 12:20:02 +02:00
Mattias Wadman c1d885b024 website: Make latest release (1.7) be default manual (#3130)
Fixes issue with confusion about features that has not been
released yet.

Move deveopment manual.yml to dev/manual.yml
Symlink manual.yml to v1.7/manual.yml
Refactor to share history header with links to other manual versions.
Change man.test and man page generation to use dev/manual.yml

Related to #3078 #3127
2024-07-12 17:43:02 +02:00
riastradh 2ee20ca604 Avoid ctype.h abuse: cast char to unsigned char first.
fix #3151
2024-07-11 23:17:06 +02:00
dependabot[bot] e2ffb5360a build(deps): bump zipp from 3.16.2 to 3.19.1 in /docs
Bumps [zipp](https://github.com/jaraco/zipp) from 3.16.2 to 3.19.1.
- [Release notes](https://github.com/jaraco/zipp/releases)
- [Changelog](https://github.com/jaraco/zipp/blob/main/NEWS.rst)
- [Commits](https://github.com/jaraco/zipp/compare/v3.16.2...v3.19.1)

---
updated-dependencies:
- dependency-name: zipp
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-11 09:18:50 +02:00
dependabot[bot] ba741e5968 build(deps): bump docker/build-push-action from 5 to 6 (#3143)
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 5 to 6.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v5...v6)

---
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>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-25 08:30:43 +09:00
Samar Sunkaria 7be6870751 Remove multiple calls to free when successively calling jq_reset. (#3134)
`jq_reset` calls `jv_free` on the `exit_code` and the `error_message` stored on the jq state.
However, it doesn't replace the actual instance of those members. This means that subsequent
calls to `jq_reset` will call `jv_free` again on those members, which in turn may call `free`
on the same pointer multiple times. Freeing the same pointer multiple times is undefined
behavior and can cause heap corruption, which is how I spotted this issue.

In practice, this issue only occurs when using a program that may `halt_error`, because that
is when the `exit_code` and `error_message` are set to values other than `jv_invalid`.
Subsequent attempts to call `jq_start` (which calls `jq_reset` internally) after hitting a
`halt_error` can cause you to run into this issue.

The changes simply reset the `exit_code` and the `error_message` to `jv_invalid` (the initial
value set in `jq_init`) after they are freed.
2024-06-05 13:19:08 +09:00
Christoph Anton Mitterer 5208a4425f fix option parsing of --binary on non-Windows platforms (#3131)
`-b`/`--binary` should be accepted on all platforms so that they can be used in
code that is meant to be portable.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2024-05-30 08:21:10 +09:00
J. B. Rainsberger 7cd23f1f2f Improve formatting of the build instructions.
Line up the comments, because reasons. :)
2024-05-21 10:35:37 -05:00
J. B. Rainsberger 4842146e1b Add "make clean" to build instructions
When I tried to build a new version in the same working directory I'd used to build a previous version, I saw build errors. After a few attempts, I remembered that "make clean" might get past the problem. It seems like a nice thing to suggest to everyone who might fall into the same trap.
2024-05-21 10:35:37 -05:00
Nicolas Williams 6d02d53f51 Make tests pass when --disable-decnum 2024-05-15 12:48:00 -05:00
dependabot[bot] c1276169d6 build(deps): bump jinja2 from 3.1.3 to 3.1.4 in /docs
Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.3 to 3.1.4.
- [Release notes](https://github.com/pallets/jinja/releases)
- [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst)
- [Commits](https://github.com/pallets/jinja/compare/3.1.3...3.1.4)

---
updated-dependencies:
- dependency-name: jinja2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-07 01:56:22 +02:00
sheepsterandSheepster ed8f7154f4 doc(readme): Fix docker run with mounted volume command (#3105)
Co-authored-by: Sheepster <sheepstert>
2024-05-01 17:56:48 +02:00
Emanuele Torre 9afc450930 COPYING: adding missing line from decNumber's licence
Fixes #3079

Also clarify what files the Kungliga Tekniska Högskolan copyright notice
applies to.
2024-05-01 16:41:44 +02:00
sheepsteranditchyny d875ff5c7a doc(readme): Add docker usage doc (#3103)
* doc(readme): Add docker usage doc

* fix heading size

Co-authored-by: itchyny <itchyny@cybozu.co.jp>
2024-05-01 06:07:10 +02:00
goodactive 6ce6e7c713 chore: fix some typos in comments (#3096)
Signed-off-by: goodactive <goodactive@qq.com>
2024-04-29 21:03:46 +02:00
Andy Lester e4d0b12d7d A couple of teeny tweaks (#3091)
* Don't get HOMEDRIVE unless needed

* Use put_char instead of put_str
2024-04-23 16:10:42 +09:00
Fabian Dellwing 6eff31a204 Add strptime fallback not only for Windows 2024-04-18 01:38:29 +02:00
maflcko 6408338e93 Update jq_fuzz_load_file.c: Add missing include unistd.h (#3085) 2024-03-29 10:13:25 +01:00
Emanuele Torre 5bbd02f581 jv_setpath: fix leak when indexing an array with an array
arrays[arrays] is a special case of "INDEX" that actually returns an
array containing the indices in which the array that is being indexed
contains the start of the key array.

So array keys, for array values, are a kind of key that can be "got",
but not "set". jv_setpath() was not freeing the value it "got" from
indexing that key, in case the following "set" on that key failed,
resulting in a leak.

    $ ./jq -n '[] | setpath([[1]]; 1)'
    jq: error (at <unknown>): Cannot update field at array index of array

    =================================================================
    ==953483==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 272 byte(s) in 1 object(s) allocated from:
        #0 0x725f4d4e1359 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x5ec17b1a7438 in jv_mem_alloc src/jv_alloc.c:141

    SUMMARY: AddressSanitizer: 272 byte(s) leaked in 1 allocation(s).

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66061
2024-03-28 18:10:38 +01:00
Mattias Wadman afe0afaf06 ci: Remove unnecessary apt-get upgrade (#3082)
Causes update to irrelevant packages and added flakeyness

Fixes #3066
2024-03-28 14:01:03 +01:00
Emanuele Torre ce2638af40 jv_aux.c: replace jv_array_foreach with regular loop in jv_dels()
The code was only conditionally using the value
2024-03-28 12:12:39 +01:00