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

1279 Commits

Author SHA1 Message Date
3c4fcb1594 Add pkg-config file for libjq
pkg-config is a common interface to resolve build details. It will
become easier to incorporate libjq in other projects by providing this
interface.
2019-03-29 08:16:36 -05:00
b52fc1043b Fix assert in generator subexpressions (fix #1875)
Expressions of the form `path(EXPR) | select(GENERATOR)`, where `EXPR`
is a path expression and `GENERATOR` is a generator conditional
expression (e.g., `has("a"), has("b")`) cause an assertion if the
jq_state VM is torn down too soon.  That assert() was only correct if
assuming that the conditional is not a generator.

If the conditional is generator, then what we see is that when
backtracking a SUBEXP_END is executed without a corresponding
SUBEXP_BEGIN because the entire conditional is bracketed with
SUBEXP_BEGIN and SUBEXP_END, and since it's resumed in the middle, in
between the brackets.

Rather than assert that the jq->path_len being restored has some
particular value, we can simply re-compute it from the restored
jq->path.
2019-03-26 18:58:55 -05:00
b34af08f67 Fix tests/jq.test for c72ed135 2019-03-25 09:56:53 -05:00
e01398c9db Fix tests/shtest broken by 2b4d51f 2019-03-25 09:52:42 -05:00
dffba62e13 Disable docs by default; don't mantest if no docs 2019-03-24 23:36:50 -05:00
2b4d51f697 Identify progname in more errors (fix #1860)
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-24 23:36:18 -05:00
0dab2b18d7 Add -b / --binary option for Windows 2019-03-24 23:23:16 -05:00
3e0a118886 Allow .["foo"].["bar"] 2019-03-24 23:23:16 -05:00
c72ed135e4 Allow keywords in more places (fix #1868) 2019-03-24 23:19:09 -05:00
3ea0199e03 Restore cfunction arity in builtins/0
Count arguments up-front at definition/invocation instead of doing it at
bind time, which comes after generating builtins/0 since e843a4f.
2019-02-26 22:39:57 -06:00
abed751e96 Bind libraries backward for consistent shadowing 2019-02-26 21:57:08 -06:00
141bb78e96 Fix regression on ~/.jq being a directory 2019-02-26 21:57:08 -06:00
30afc86af1 Fix alpine build 2019-02-26 21:40:59 -06:00
6df393c902 Make shtest verbose 2 diag. alpine build failure
Temporarily(?) make tests/shtest verbose to help diagnose Travis alpine
build failures.
2019-02-26 11:17:20 -06:00
f951d0241c Change contains to return true for empty string needles
The behavior of memmem for an empty needle is inconsistent between
implementations of libc.
Our tests imply that we want an empty string needle to be true,
so check for an empty needle before calling memmem.
2019-02-26 11:10:38 -06:00
cc724f105d Configure appveyor build to use python 2019-02-26 11:10:38 -06:00
a4756fde3f Cleanup leftover references to ruby 2019-02-26 11:10:38 -06:00
15be4e7915 Configure travis build to use python 2019-02-26 11:10:38 -06:00
53a3f47076 Remove ruby dependency from mantests 2019-02-26 11:10:38 -06:00
175dbc4e25 Remove ruby dependency from manpage build 2019-02-26 11:10:38 -06:00
c1f11855e3 Remove ruby dependency from website build 2019-02-26 11:10:38 -06:00
76e72a301d Simplify and optimize SQLish builtins 2019-02-26 11:05:25 -06:00
a1626adb7e Fix bizarre bsearch/1 behaviour with a stream argument 2019-02-26 11:05:25 -06:00
d1a07cbdc1 Make tostream much more efficient
(`path(.[])` is a streaming `keys`!)
2019-02-26 11:05:25 -06:00
8c1e7175ec Reimplement fromstream/1 more compactly 2019-02-26 11:05:25 -06:00
fc6df0fdc1 Simplify definition of range/3
New implementation in terms of while/2, and branches immediately on $by
to avoid checking the sign of $by *in* the loop.
2019-02-26 11:05:25 -06:00
78271b179a Simplify type-select builtins 2019-02-26 11:05:25 -06:00
d3abe3a468 Add more tests for any and all 2019-02-26 11:05:25 -06:00
41b859325b Redefine isempty/1, and the all and any series
Fixes the bug where all and any evaluate one more item than needed.
2019-02-26 11:05:25 -06:00
6a0bdf6063 Remove scalars_or_empty 2019-02-26 11:05:25 -06:00
36c250a03d No need to block_drop_unreferenced after builtins
(The correctness of this change is more obvious after the rename.)
2019-02-26 10:49:08 -06:00
260879a5c3 Rename block_bind_incremental to block_bind_referenced
block_bind_incremental is block_bind_referenced in a loop backwards. For
an 1-inst block, it does the same thing and isn't too much more
expensive, so it's not really useful to keep both.

Also, block_bind_referenced was a better name for the function.
2019-02-26 10:49:08 -06:00
8537b93a43 Fix block flipping in block_drop_unreferenced
Since 605bfb3, block_drop_unreferenced actually reverses the order of
instructions in the block it's run against. This bug was hidden by the
fact that normally it's run *twice* against the main program, flipping
it back, and that order of function definitionss doesn't really matter
after symbol resolution.
2019-02-26 10:49:08 -06:00
9a0d5be790 Merge pull request #1837 from muhmuhten/limit_0 2019-02-21 08:17:41 -06:00
130152a2ac Ensure limit(0; ...) is empty 2019-02-21 04:11:41 -05:00
730c730940 Rewrite _assign/2 using $argument syntax 2019-02-20 20:12:52 -06:00
85caac4473 Work around fgets()'s lack of length reporting
Stop losing \0s from the end of files because we don't know how much
fgets() read into our buffer. If we prefill the buffer with anything
other than zeroes, we can actually tell the difference between the
terminator and unused space in the buffer.

This is possibly more expensive, but at least it should be correct.

Fixes #1504
2019-02-20 20:12:52 -06:00
048acee39b Fix if-then-else example formatting 2019-02-20 20:03:26 -06:00
8a02b2c9c1 Document optional else clause of if 2019-02-20 20:03:26 -06:00
4f6045a94e Support "if" without "else" clause
Defaults the else clause to the identity filter "." if an else clause is
missing.

The following two jq programs are considered equivalent:

```
if .foo then
    .foo = "bar"
else
    .
end
```

```
if .foo then
    .foo = "bar"
end
```
2019-02-20 20:03:26 -06:00
1ef90acb38 Bind data imports properly when already resolved 2019-02-20 20:02:41 -06:00
e843a4fdf9 Make builtin binding fast again by binding only referenced symbols
Avoid doing the internal binding of top-level symbols in the parser,
leaving that work to be done in a post-processing step. For builtins,
this lets us do a reference-aware bind step (block_bind_incremental)
*after* generating builtins/0.

Libraries are a bit trickier since they may be bound multiple times, so
instead of thinking through the implications I added (block_bind_self)
to resolve all internal symbols immediately.
2019-02-20 19:43:13 -06:00
b2b0bd37a1 Load ~/.jq as a library instead of with builtins
Remove the special code which loads ~/.jq in builtin.c, and instead glue
an optional include which points to the same file onto the main program
in linker.c.

Fixes a minor bug where errors in ~/.jq would be labelled <builtin>.
2019-02-20 19:16:18 -06:00
450ade4818 Add import metadata key "optional"
A library marked is imported if found, but silently skipped if missing.
This is the desired semantic for the auto-include at ~/.jq
2019-02-20 19:16:18 -06:00
c814c4e001 Replace TOP-before-imports special case with assert
The case isn't actually possible afaict.
2019-02-20 19:16:18 -06:00
4f4494c770 Catch .. as the first component of a module path
Only the second and subsequent path components were being checked, which
I guess is theoretically security-relevant.

There's no apparent point to reconstructing the path after splitting it
by adding /s back in, either.
2019-02-20 19:16:18 -06:00
ff014824bc Pass on the error message when rel_path is invalid
"Module path must be a string" is not a useful error message when the
reason the module path isn't a string is because the string it was got
replaced with an invalid with an error message for some other reason.

Also fixes a few memory leaks on early exits.
2019-02-20 19:16:18 -06:00
8edf58a95f Simplify definition of block_bind_referenced 2019-02-20 19:16:18 -06:00
88e1f59ec1 Allow globbing on Windows
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-17 23:58:23 -06:00
80b064f97b Make UTC time on Windows
Windows has `_mkgmtime` for the UTC equivalent of `mktime`.
2019-02-16 20:42:25 -06:00