Skip to content

fix: prevent panic on empty-string values in v2 JSON fixtures#1736

Open
arpitjain099 wants to merge 1 commit into
stripe:masterfrom
arpitjain099:chore/v2-fixture-empty-string
Open

fix: prevent panic on empty-string values in v2 JSON fixtures#1736
arpitjain099 wants to merge 1 commit into
stripe:masterfrom
arpitjain099:chore/v2-fixture-empty-string

Conversation

@arpitjain099

Copy link
Copy Markdown

Reviewers

r?
cc @stripe/developer-products

Summary

An empty-string value in a v2 (application/json) fixture crashes the CLI with "slice bounds out of range [:1] with length 0". In parseMapForApplicationJSON the code checks whether a value looks like a JSON array or object with parsed[0:1] and parsed[len(parsed)-1:], and those slice both blow up on a zero-length string. This happens whenever a fixture field is set to "" or a query/env lookup resolves to empty.

The fix swaps those two checks for strings.HasPrefix/HasSuffix, which return false on empty input, so an empty value just falls through and is stored as "". That matches how the form-data path already handles it. I added a regression test that passes an empty-string value through ParseToApplicationJSON; it panics before this change and passes after. Full pkg/parsers suite and go vet are green.

Thanks for taking a look.

parseMapForApplicationJSON sniffed whether a value looks like a JSON
array or object with parsed[0:1] and parsed[len(parsed)-1:]. When a v2
(application/json) fixture field resolves to an empty string, those
slice expressions index a zero-length string and the CLI panics with
"slice bounds out of range [:1] with length 0".

Use strings.HasPrefix/HasSuffix instead, which return false on empty
input, so an empty value falls through to the default branch and is
stored as "" (the same way the form-data path already handles it).

Added a regression test covering an empty-string value in the
application/json path.

Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
@arpitjain099 arpitjain099 requested a review from a team as a code owner July 3, 2026 15:02
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.

1 participant