Skip to content

findValOfKey regex silently truncates JSON values  #63

@mdryaan

Description

@mdryaan

Description

findValOfKey in tests/e2e/common.go extracts JSON values using a regex:

keystr := "\"" + key + "\":[^,;\\]}]*"

The character class [^,;\\]}]* stops at the first comma, semicolon, ], or }. This silently truncates any value containing those characters, returning wrong data without any error.

Steps to Reproduce

cd /mnt/c/Users/alikh/Desktop/Projects/urunc_test
go test ./tests/e2e/ -run TestFindValOfKey -v

Output:

Image

Expected Behavior

findValOfKey should return the correct value for any valid JSON, regardless of value complexity.

Current Behavior

The regex stops at the first comma inside a string value ("foo,bar"foo) and at the first } in a nested object, then the split-on-colon further mangles the result ({"IPAddress":"172.17.0.2"}{IPAddress).

Proposed Solution

Replace the regex with encoding/json unmarshalling and a recursive key search.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions