You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because regular expressions in a `jq` query are strings, their `\`
escapes must be written as `\\`. But the `get-metadata` recipe in
the `justfile` is strangely intolerant of `\\` in a cross-platform
setting. On Windows, even though `sh` is used on both, and even
though the `quote()` function is supposed to work the same way on
both, the `\\` gets folded into `\` in the actual query argument
passed to `jq`, and `just msrv` fails with:
cargo metadata --format-version 1 --no-deps | jq --exit-status --raw-output -- '.packages[] | select(.name == "gix") | .rust_version | sub("^\\d+\\.\\d+\\K$"; ".0")'
jq: error: Invalid escape at line 1, column 4 (while parsing '"\d"') at <top-level>, line 1:
.packages[] | select(.name == "gix") | .rust_version | sub("^\d+\.\d+\K$"; ".0")
jq: error: Invalid escape at line 1, column 6 (while parsing '"\.\d"') at <top-level>, line 1:
.packages[] | select(.name == "gix") | .rust_version | sub("^\d+\.\d+\K$"; ".0")
jq: error: Invalid escape at line 1, column 4 (while parsing '"\K"') at <top-level>, line 1:
.packages[] | select(.name == "gix") | .rust_version | sub("^\d+\.\d+\K$"; ".0")
jq: 3 compile errors
error: Recipe `get-metadata` failed on line 191 with exit code 3
A Windows-specific workaround is to write `\\\\` instead of `\\`.
This works on Windows, but of course breaks on other platforms
where it represents a subpattern of `\\` and thus matches only a
literal `\` (which is not present and shouldn't be matched if it
were).
In this case, it so happens that the pattern was also potentially
confusing for other reasons, due to the way it matched a zero-width
string after a `\K`-discarded sub-match that did most of the work.
Because `\\d` and `\\.` are easily replaced with character classes
that use no `\`, the `\\K` was the only use of `\` in the pattern
string that needed `\`.
So this replaces that technique with a different more readable one
that does not require writing any occurrences of `\\`. (It uses a
`\`, but no `\\`, and `\` by itself seems to cause no problems.)
Instead of discarding a sub-match and replacing an empty string,
this matches on the entire string (if in MAJOR.MINOR form) and
replaces the whole thing with itself followed by `.0`.
This does make the recipe longer. The `jq` query argument is
accordingly now split over multiple lines. (Although this is done
using a `'''` string instead of a `'` string, that does not make a
difference to the misinterpretation of `\\`, which occurs after the
string has been received by the `get-metadata` recipe.)
0 commit comments