Description
fastjq rejects jq comments (#) in every position. jq 1.8.1 and gojq both accept them.
This isn't listed under Limitations in the README, and docs/SYNTAX.md doesn't mention
comments at all — so a caller migrating a working jq program has no warning. It bites
hardest when queries are authored by humans in a config file or UI, where a trailing
# why this filter exists is completely ordinary.
Reproducer
package main
import (
"fmt"
"github.com/DataDog/fastjq"
)
func main() {
for _, q := range []string{
`.foo = "baz" # set foo`,
"# set foo\n.foo = \"baz\"",
".foo = \"baz\"\n# trailing note",
".a # mid\n| .b",
} {
_, err := fastjq.Compile(q)
fmt.Printf("%-28q -> %v\n", q, err)
}
}
Expected output: all four compile; comments are stripped as whitespace.
$ echo '{}' | jq '.foo = "baz" # set foo'
{
"foo": "baz"
}
Actual output:
".foo = \"baz\" # set foo" -> unexpected trailing input: "# set foo"
"# set foo\n.foo = \"baz\"" -> unexpected character "#"
".foo = \"baz\"\n# trailing note" -> unexpected trailing input: "# trailing note"
".a # mid\n| .b" -> unexpected trailing input: "# mid\n| .b"
Suggested fix
Comment skipping belongs in the scanner's whitespace handling: on #, consume to the next
\n or end of input. jq's rule is that # starts a comment except inside a string literal,
and a backslash-newline continuation does not extend a comment (jq 1.7+ treats \ at end
of a comment line literally). The common cases are the four above.
If comments are out of scope by design, listing them under Limitations next to the
regex/decnum notes would be enough to save the next migrator the debugging.
Environment
- fastjq version:
c3336f252fa23bbda9a611024f6398904330cd9a (master, untagged)
- Go version:
go version go1.25.4 darwin/arm64
- OS / arch: macOS, arm64
Description
fastjq rejects jq comments (
#) in every position. jq 1.8.1 and gojq both accept them.This isn't listed under Limitations in the README, and
docs/SYNTAX.mddoesn't mentioncomments at all — so a caller migrating a working jq program has no warning. It bites
hardest when queries are authored by humans in a config file or UI, where a trailing
# why this filter existsis completely ordinary.Reproducer
Expected output: all four compile; comments are stripped as whitespace.
Actual output:
Suggested fix
Comment skipping belongs in the scanner's whitespace handling: on
#, consume to the next\nor end of input. jq's rule is that#starts a comment except inside a string literal,and a backslash-newline continuation does not extend a comment (jq 1.7+ treats
\at endof a comment line literally). The common cases are the four above.
If comments are out of scope by design, listing them under Limitations next to the
regex/decnum notes would be enough to save the next migrator the debugging.
Environment
c3336f252fa23bbda9a611024f6398904330cd9a(master, untagged)go version go1.25.4 darwin/arm64