-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scan() with grouping returns empty string #14
Comments
Use the following Dockerfile to reproduce the issue:
> docker build -t ruby-with-jq .
> docker run -it ruby-with-jq irb -r jq JQ('{ "foo": "thisthat" }').search('.foo | scan("this(.+)")') # => [[""]] |
I investigated this further by adding Running
As you can see the last line shows an empty capture. I wrote a simple C program to test libjq and to imitate the code in #include <stdio.h>
#include <string.h>
#include <jq.h>
int main(){
jq_state *jq = NULL;
jq = jq_init();
char *buf = "\"foobar\"";
char *prog = "scan(\"foo(.+)\")";
jv input = jv_parse(buf);
int compiled = jq_compile(jq, prog);
jq_start(jq, input, JQ_DEBUG_TRACE);
jv result;
result = jq_next(jq);
jv dumped = jv_dump_string(result, 0);
const char *str = jv_string_value(dumped);
printf("OUTPUT: %s\n", str);
jq_teardown(&jq);
printf("Done!\n");
return 0;
} Running this program gives:
The capture works and the output is I still have no idea why it acts differently. Btw, all of this was run inside the Docker container (specified above). |
I have a pretty similar problem (i suppose). ruby-jq gives me different output on my local machine and on production machine (docker-based). Local:
Production:
Notice that month on production is actually mapped to a day so it's working entirely wrong from top to bottom. My Dockerfile:
And similar as in above comments, running the query directly via command line gives me a correct result:
|
@mbajur I solved my issue by compiling a different version of JQ that uses onigmo (like Ruby 2.0 or later) instead of oniguruma. You can find it here: https://github.com/voke/jq |
thank you @voke ! I finally dropped jq entirely (partially because of the fact this gem seems to be abandoned) |
Had this problem as well. Compiling onigmo + voke-jq, then gem installing with |
This is indeed a strange issue which I could reproduce. System libraries or not, whenever I linked against oniguruma captures never worked right (always a blank capture before the actual capture). #20 should just build without any external dependencies against onigmo. |
I'm having a case where
scan()
returns empty string.Using the jq command:
Output:
[ "that" ]
Using ruby-jq gem:
I can only reproduce the problem when deployed to heroku. To reproduce the problem click the deploy button at https://github.com/voke/heroku-jq-debugger (which includes the libjq 1.6 buildpack)
Run
heroku run console --app YOUR_APP_NAME
and follow the steps above.First I thought it must be an oniguruma issue since regexp is used. But
gsub
command works as expected.My second guess was that since my local version of jq (installed via homebrew) and the ruby-jq gem returns the correct output the problem must be within my buildpack. But running the jq command at heroku also returns the correct output.
heroku run "cd jq && echo '{ \"foo\": \"thisthat\" }' | ./jq '.foo | scan(\"this(.+)\")'" --app YOUR_APP_NAME
Output:
Do you have any idea what the issue may be?
The text was updated successfully, but these errors were encountered: