Skip to content
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

jsonnetfmt panics on regex string #606

Open
harsimranmaan opened this issue May 9, 2022 · 1 comment
Open

jsonnetfmt panics on regex string #606

harsimranmaan opened this issue May 9, 2022 · 1 comment
Labels

Comments

@harsimranmaan
Copy link
Contributor

Repro steps:

$ brew install go-jsonnet
==> Downloading https://ghcr.io/v2/homebrew/core/go-jsonnet/manifests/0.18.0
...
$ echo "{a : '^/v1/abc-[\w-.]+/xyz/[\w-.]+$'}" > a.jsonnet
$ jsonnetfmt a.jsonnet
panic: Badly formatted string, should have been caught in lexer.

goroutine 1 [running]:
github.com/google/go-jsonnet/internal/formatter.(*EnforceStringStyle).LiteralString(0x140000f8090, {0x1045014b0, 0x140000f8090}, 0x140000ec210, {0x0, 0x0})
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/formatter/enforce_string_style.go:45 +0x1c8
github.com/google/go-jsonnet/internal/pass.(*Base).Visit(0x140000f8090, {0x1045014b0, 0x140000f8090}, 0x140000fc170, {0x0, 0x0})
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/pass/pass.go:433 +0x294
github.com/google/go-jsonnet/internal/pass.(*Base).ObjectField(0x140000f8090, {0x1045014b0, 0x140000f8090}, 0x140000fc0f0, {0x0, 0x0})
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/pass/pass.go:162 +0x10c
github.com/google/go-jsonnet/internal/pass.(*Base).ObjectFields(0x140000f8090, {0x1045014b0, 0x140000f8090}, 0x140000ec330, {0x0, 0x0})
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/pass/pass.go:193 +0x6c
github.com/google/go-jsonnet/internal/pass.(*Base).Object(0x140000f8090, {0x1045014b0, 0x140000f8090}, 0x140000ec2c0, {0x0, 0x0})
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/pass/pass.go:333 +0x58
github.com/google/go-jsonnet/internal/pass.(*Base).Visit(0x140000f8090, {0x1045014b0, 0x140000f8090}, 0x1400008e710, {0x0, 0x0})
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/pass/pass.go:437 +0x824
github.com/google/go-jsonnet/internal/pass.(*Base).File(0x140000f8090, {0x1045014b0, 0x140000f8090}, 0x1400008e710, 0x1400009c138)
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/pass/pass.go:463 +0x74
github.com/google/go-jsonnet/internal/formatter.visitFile(...)
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/formatter/jsonnetfmt.go:144
github.com/google/go-jsonnet/internal/formatter.Format({0x16baff883, 0x9}, {0x140000f8000, 0x26}, {0x2, 0x2, 0x1, 0x1, 0x1, 0x0, ...})
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/internal/formatter/jsonnetfmt.go:183 +0x4ac
main.main()
	/private/tmp/go-jsonnet-20211221-89224-l130j1/go-jsonnet-0.18.0/cmd/jsonnetfmt/cmd.go:289 +0x64c

Originally found via splunk/qbec#284

Caused by the \w in the string value

@netomi
Copy link
Contributor

netomi commented Aug 12, 2023

The suggested fix in the PR for #551 also fixes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants