1980 Commits
Author SHA1 Message Date
itchyny 4003202ccf Fix segmentation fault on strftime/1 and strflocaltime/1 (#3271)
When we use a large format string to `strftime/1` and `strflocaltime/1`,
we get segmentation fault. This happens because the result buffer is
allocated on the stack using `alloca` function, and `strftime` function
writes out of the space when the size is not enough to format time.
I fixed the segmentation fault issue by allocating the result buffer on
the heap using `malloc` function, because `alloca` function does not
provide a way to detect insufficient space.
2025-03-04 22:28:09 +09:00
itchyny dc849e9bb7 Improve performance of repeating strings (#3272)
This commit improves the performance of repeating strings, by copying
the result string instead of the string being repeated. Also it adds
an error message when the result string is too long.
2025-03-04 22:13:55 +09:00
itchyny 5df471fa5b Disable Valgrind by default during testing (#3269)
Previously, the configure script automatically enables Valgrind during
testing when the valgrind command is found. However, running tests with
Valgrind is quite slow, so it is better to disable it by default, and
to enable it only when the user specifies the `--enable-valgrind` flag.
2025-03-04 22:12:25 +09:00
itchyny c4e1fb08fb Support CRLF line breaks in filters (#3274) 2025-03-04 22:11:40 +09:00
itchyny b7a1201b72 Preserve numerical precision on length/0 (#3275) 2025-03-04 22:09:33 +09:00
itchyny 17be97a8ad Define _BSD_SOURCE in builtin.c for OpenBSD support (#3278)
On OpenBSD, some prototypes are hidden behind `_BSD_SOURCE`.
Defining this variable fixes #3252, and also fixes #3276.
This can be seen as a regression of #2631.
2025-03-04 21:39:52 +09:00
itchyny 95ee663b28 improve performance of unique and unique_by (#3254)
Previously, `unique` and `unique_by` filters are implemented using
`group_by` and then `map(.[0])`. This commit re-implements in C, to
avoid unnecessary boxing of grouping, and improves the performance.
2025-03-04 19:59:41 +09:00
Owen Ou 8ba03f788f Replace jqplay.org with play.jqlang.org (#3265)
As discussed in https://github.com/jqlang/jq/discussions/3244, we are
moving jqplay to the jqlang GitHub organization. This updates all
references from jqplay.org to play.jqlang.org.
2025-02-18 08:22:05 +09:00
Marcin Serwin f3d4c1165d fix: copy the string returned by getenv (#3264) 2025-02-18 07:54:13 +09:00
itchyny 70e72abea3 Fix compiler warning type-limits in found_string (ref #2911) (#3263)
Whether `char` has a sign is implementation dependent, and `c >= 0` may
result in a compiler warning. We can use bitwise operator to check
whether the character is a control character, regardless of the sign.
2025-02-18 07:52:58 +09:00
Marcin Serwin 6d8e9f98ae fix: populate timezone data when formatting time (#3203)
The `jv2tm` function was zeroing fields of `struct tm` that were not
specified by the standard. However, depending on the libc this produced
incorrect timezone data when used together with formatting functions.
This change tries to fill the timezone data using either `mktime`,
`timegm`, or manually.

Apple's Libc implementation contains a bug which causes it to ignore
the offset data present in the `struct tm` in favor of the older heuristic
needed by legacy standards. This workaround temporarily sets the global
timezone so it gets picked up during formatting.
2025-02-17 21:41:01 +09:00
itchyny b86ff49f46 fix: jv_number_value should cache the double value of literal numbers (#3245)
The code of `jv_number_value` is intended to cache the double value of
literal numbers, but it does not work because it accepts the `jv` struct
by value. This patch fixes the behavior by checking if the double value
is `NaN`, which indicates the unconverted value. This patch improves the
performance of major use cases; e.g. `range(1000000)` runs 25% faster.
2025-02-16 22:08:36 +09:00
itchyny 64bd8ba374 fix: jv_dump_string_trunc should not break unicode characters (#3249) 2025-02-16 21:40:18 +09:00
itchyny fa6a2ff688 website: remove unused root path on building website (#3248)
We no longer use the `--root` option of `build_website.py` since we have
moved to jqlang.org (from jqlang.github.io/jq where the root was `/jq`).
We don't need the option on local development either since `http.server`
has the `-d` option to specify the directory to serve from.
2025-02-06 22:42:27 +09:00
Mattias Wadman e33578a53e Add opengraph meta tags (#3247)
Makes the site preview a bit nicer when sharing
2025-02-06 22:14:29 +09:00
itchyny 6ce3bdf382 fix: preserve numerical precision on unary negation (#3242) 2025-02-06 07:50:21 +09:00
itchyny 972772153f Move oniguruma and decNumber to vendor directory (#3234) 2025-02-06 07:49:56 +09:00
Mattias Wadman 2755664a8e Non-matched optional capture group should be null and offset -1 (#3238)
Fixes #3093
2025-02-04 19:18:58 +01:00
d0adcbfebb Fix --indent 0 implicitly enabling compact-output (#3232)
Now it will retain pretty-printing, just remove any indentation.

Co-authored-by: Andrew Marshall <andrew@johnandrewmarshall.com>
Co-authored-by: Gabriel Marin <marin.gabriel@protonmail.com>
2025-02-01 15:09:30 +09:00
orbea 07af9c11b7 build: fix insecure RUNPATH (#3212)
The -static-libtool-libs flag causes GNU libtool to add a rpath to the .libs
build directory, which is intended for internal use by the libtool
implementation and is not installed in the resulting package causing Gentoo to
print a QA notice. See Gentoo issue: https://bugs.gentoo.org/945698.
2025-02-01 15:07:54 +09:00
itchyny 0d1e371e63 website: switch to custom domain jqlang.org (#3243) 2025-02-01 11:54:32 +09:00
itchyny dea5e61cde docs: fix example links to jqplay.org (#3241) 2025-01-28 22:15:19 +09:00
itchyny ce54621904 docs: mention the behavior of scan using regex with capturing groups (#3240) 2025-01-28 11:41:17 +09:00
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