Blacksmoke16 / oq

A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
https://blacksmoke16.github.io/oq/
MIT License
190 stars 15 forks source link

`--arg` handling broken for certain variable names with jq 1.6 #78

Closed bobbwest closed 3 years ago

bobbwest commented 3 years ago

When using a specific variable name (I've found config to be an issue) with --arg, oq fails with jq 1.6, but works with jq 1.5:

jq 1.5:

$ oq --version
jq: jq-1.5-1-a5b5cbe
oq: 1.2.0
$ oq -i json -o json -n --arg config foo '$config' /dev/null
"foo"

jq 1.6:

$ oq --version
jq: jq-1.6
oq: 1.2.0
$ oq -i json -o json -n --arg config foo '$config' /dev/null
jq: --arg takes two parameters (e.g. --arg varname value)
Use jq --help for help with command-line options,
or see the jq manpage, or online docs  at https://stedolan.github.io/jq

Strangely it works for other variable names:

$ oq --version
jq: jq-1.6
oq: 1.2.0
$ oq -i json -o json -n --arg c foo '$c' /dev/null
"foo"
Blacksmoke16 commented 3 years ago

@bobbwest Hmm, I tried reproducing this both on Linux and Mac and I was unable to:

$ oq -V
jq: jq-1.6
oq: 1.2.0

$ oq -i json -o json -n --arg config foo '$config' /dev/null
"foo"

What OS are you on? How did you install jq? Is it possible it's something with that jq binary?

EDIT: Also, out of curiosity what happens if you just run jq -n --arg config foo '$config' /dev/null? Does that also cause the issue?

bobbwest commented 3 years ago

Ok, that's interesting.

I'm using virgin Ubuntu 20.04 (packages fully updated), jq installed with apt-get install jq, oq installed by downloading the binary from GitHub.

I've isolated the issue to the existence of a directory with the same name as the variable used with --arg:

$ wget https://github.com/Blacksmoke16/oq/releases/download/v1.2.0/oq-v1.2.0-linux-x86_64
$ chmod +x ./oq-v1.2.0-linux-x86_64
$ ./oq-v1.2.0-linux-x86_64 --version
jq: jq-1.6
oq: 1.2.0

# this works:
$ ./oq-v1.2.0-linux-x86_64 -n --arg config foo '' /dev/null
null

# but not if a directory with the same name as the arg exists:
$ mkdir config
$ ./oq-v1.2.0-linux-x86_64 -n --arg config foo '' /dev/null
jq: --arg takes two parameters (e.g. --arg varname value)
Use jq --help for help with command-line options,
or see the jq manpage, or online docs  at https://stedolan.github.io/jq

# remove directory and it works:
$ rmdir config
$ ./oq-v1.2.0-linux-x86_64 -n --arg config foo '' /dev/null
null

The issue is not (specifically) with jq, as it works fine with the directory:

$ mkdir config
$ jq -n --arg config foo '' /dev/null
null
Blacksmoke16 commented 3 years ago

I've isolated the issue to the existence of a directory with the same name as the variable used with --arg:

:pray: This is super helpful thanks