Skip to content

fix: replace regex in findValOfKey with JSON parsing#65

Open
mdryaan wants to merge 1 commit into
urunc-dev:mainfrom
mdryaan:fix/find-val-of-key-json-parsing
Open

fix: replace regex in findValOfKey with JSON parsing#65
mdryaan wants to merge 1 commit into
urunc-dev:mainfrom
mdryaan:fix/find-val-of-key-json-parsing

Conversation

@mdryaan
Copy link
Copy Markdown

@mdryaan mdryaan commented May 15, 2026

Description

findValOfKey in tests/e2e/common.go extracted JSON values using a regex ([^,;\\]}]*) that stops at the first comma, semicomp, ], or }. This silently returns truncated data for any JSON value containing those characters — string values with commas are truncated, and nested object values are mangled beyond use.

This replaces the regex with encoding/json unmarshalling and a recursiv key search (searchJSONKey), with jsonValToString for type-safe value serialization back to string.

Related issues

How was this tested?

TestFindValOfKey in tests/e2e/common_test.go was added with 5 subtests.

Before the fix, two fail:

Screenshot 2026-05-15 214758

After the fix, all 5 pass:

Screenshot 2026-05-15 222151

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

Signed-off-by: Md Raiyan <alikhurshid842001@gmail.com>
@mdryaan
Copy link
Copy Markdown
Author

mdryaan commented May 15, 2026

Hi @cmainas Could you please review this, whenever you get chance.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

findValOfKey regex silently truncates JSON values

1 participant